@kevisual/cnb 0.0.43 → 0.0.45

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.
@@ -4,7 +4,9 @@ import { useKey } from '@kevisual/context';
4
4
  import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
5
5
  export const getConfig = async (opts: { token?: string }) => {
6
6
  const kevisualEnv = useKey('KEVISUAL_ENV')
7
- const baseUrl = kevisualEnv === 'production' ? 'https://kevisual.cn/api/router' : 'https://kevisual.xiongxiao.me/api/router';
7
+ const isCNB = useKey('CNB');
8
+ let isProduction = kevisualEnv !== 'development' || (isCNB && !kevisualEnv);
9
+ const baseUrl = isProduction ? 'https://kevisual.cn/api/router' : 'https://kevisual.xiongxiao.me/api/router';
8
10
  const res = await fetch(baseUrl, {
9
11
  method: 'POST',
10
12
  body: JSON.stringify({
@@ -70,6 +72,8 @@ export class CNBManager {
70
72
  if (token) {
71
73
  return this.addCNB({ username, token, cookie })
72
74
  }
75
+ } else {
76
+ console.error('获取 CNB 配置失败', username, res)
73
77
  }
74
78
  return null
75
79
  }
@@ -9,7 +9,7 @@ app.route({
9
9
  middleware: ['auth'],
10
10
 
11
11
  }).define(async (ctx) => {
12
- const tokenUser = ctx.tokenUser;
12
+ const tokenUser = ctx.state?.tokenUser;
13
13
  if (!tokenUser) {
14
14
  ctx.throw(401, '未授权');
15
15
  }
@@ -29,7 +29,8 @@ app.route({
29
29
  description: '获取我的cnb配置',
30
30
  middleware: ['auth'],
31
31
  }).define(async (ctx) => {
32
- const username = ctx.tokenUser?.username;
32
+ const tokenUser = ctx.state?.tokenUser;
33
+ const username = tokenUser?.username;
33
34
  const token = ctx.query?.token;
34
35
  if (!username) {
35
36
  ctx.throw(400, '未授权');
@@ -0,0 +1,6 @@
1
+ const token = 'st_logh1b3ozq2resntxlnk4bccao0bon8e'
2
+ import { CNBManager } from "../../modules/cnb-manager.ts"
3
+ const cnbManager = new CNBManager()
4
+
5
+ const cnbItem = await cnbManager.getCNB({ username: 'root', kevisualToken: token });
6
+ console.log('cnbItem', cnbItem)
package/dist/cli.js CHANGED
@@ -24105,6 +24105,8 @@ class KnowledgeBase extends CNBCore {
24105
24105
  }
24106
24106
 
24107
24107
  // src/repo/index.ts
24108
+ var import_dayjs = __toESM(require_dayjs_min(), 1);
24109
+
24108
24110
  class Repo extends CNBCore {
24109
24111
  constructor(options) {
24110
24112
  super(options);
@@ -24140,6 +24142,11 @@ class Repo extends CNBCore {
24140
24142
  const preCommitSha = commitList.length > 0 ? commitList[0].sha : undefined;
24141
24143
  if (!data.parent_commit_sha && preCommitSha) {
24142
24144
  data.parent_commit_sha = preCommitSha;
24145
+ } else if (data.parent_commit_sha) {
24146
+ if (!data.new_branch) {
24147
+ const date5 = import_dayjs.default().format("MMDDHHmm");
24148
+ data.new_branch = `refs/heads/${date5}`;
24149
+ }
24143
24150
  }
24144
24151
  const url3 = `${this.hackURL}/${repo}/-/git/commits`;
24145
24152
  const postData = {
@@ -45971,7 +45978,9 @@ function createOpenAICompatible(options) {
45971
45978
  // agent/modules/cnb-manager.ts
45972
45979
  var getConfig2 = async (opts) => {
45973
45980
  const kevisualEnv = useKey("KEVISUAL_ENV");
45974
- const baseUrl = kevisualEnv === "production" ? "https://kevisual.cn/api/router" : "https://kevisual.xiongxiao.me/api/router";
45981
+ const isCNB = useKey("CNB");
45982
+ let isProduction = kevisualEnv !== "development" || isCNB && !kevisualEnv;
45983
+ const baseUrl = isProduction ? "https://kevisual.cn/api/router" : "https://kevisual.xiongxiao.me/api/router";
45975
45984
  const res = await fetch(baseUrl, {
45976
45985
  method: "POST",
45977
45986
  body: JSON.stringify({
@@ -46017,6 +46026,8 @@ class CNBManager {
46017
46026
  if (token) {
46018
46027
  return this.addCNB({ username, token, cookie });
46019
46028
  }
46029
+ } else {
46030
+ console.error("获取 CNB 配置失败", username, res);
46020
46031
  }
46021
46032
  return null;
46022
46033
  }
@@ -60059,7 +60070,7 @@ app.route({
60059
60070
  }).addTo(app);
60060
60071
 
60061
60072
  // agent/routes/cnb-board/live/live-content.ts
60062
- var import_dayjs = __toESM(require_dayjs_min(), 1);
60073
+ var import_dayjs2 = __toESM(require_dayjs_min(), 1);
60063
60074
  import os2 from "node:os";
60064
60075
  import { execSync as execSync2 } from "node:child_process";
60065
60076
  var getLiveMdContent = (opts) => {
@@ -60273,8 +60284,8 @@ var createOSInfo = (more = false) => {
60273
60284
  description: "当前目录磁盘使用情况"
60274
60285
  });
60275
60286
  if (startTimer) {
60276
- const buildStartTime = import_dayjs.default(startTimer).format("YYYY-MM-DD HH:mm:ss");
60277
- const buildStartTimestamp = import_dayjs.default(startTimer).valueOf();
60287
+ const buildStartTime = import_dayjs2.default(startTimer).format("YYYY-MM-DD HH:mm:ss");
60288
+ const buildStartTimestamp = import_dayjs2.default(startTimer).valueOf();
60278
60289
  const buildUptime = Date.now() - buildStartTimestamp;
60279
60290
  const buildUptimeStr = formatUptime(Math.floor(buildUptime / 1000));
60280
60291
  const maxRunTime = useKey("CNB_PIPELINE_MAX_RUN_TIME") || 0;
@@ -60290,7 +60301,7 @@ var createOSInfo = (more = false) => {
60290
60301
  description: `构建已运行时间: ${buildUptimeStr}`
60291
60302
  });
60292
60303
  if (maxRunTime > 0) {
60293
- const now = import_dayjs.default();
60304
+ const now = import_dayjs2.default();
60294
60305
  const today4am = now.hour(4).minute(0).second(0).millisecond(0);
60295
60306
  let timeTo4 = today4am.valueOf() - now.valueOf();
60296
60307
  if (timeTo4 < 0) {
@@ -60844,7 +60855,7 @@ app.route({
60844
60855
  description: "清理我的cnb-manager记录",
60845
60856
  middleware: ["auth"]
60846
60857
  }).define(async (ctx) => {
60847
- const tokenUser = ctx.tokenUser;
60858
+ const tokenUser = ctx.state?.tokenUser;
60848
60859
  if (!tokenUser) {
60849
60860
  ctx.throw(401, "未授权");
60850
60861
  }
@@ -60863,7 +60874,8 @@ app.route({
60863
60874
  description: "获取我的cnb配置",
60864
60875
  middleware: ["auth"]
60865
60876
  }).define(async (ctx) => {
60866
- const username = ctx.tokenUser?.username;
60877
+ const tokenUser = ctx.state?.tokenUser;
60878
+ const username = tokenUser?.username;
60867
60879
  const token2 = ctx.query?.token;
60868
60880
  if (!username) {
60869
60881
  ctx.throw(400, "未授权");
package/dist/opencode.js CHANGED
@@ -22012,6 +22012,8 @@ class KnowledgeBase extends CNBCore {
22012
22012
  }
22013
22013
 
22014
22014
  // src/repo/index.ts
22015
+ var import_dayjs = __toESM(require_dayjs_min(), 1);
22016
+
22015
22017
  class Repo extends CNBCore {
22016
22018
  constructor(options) {
22017
22019
  super(options);
@@ -22047,6 +22049,11 @@ class Repo extends CNBCore {
22047
22049
  const preCommitSha = commitList.length > 0 ? commitList[0].sha : undefined;
22048
22050
  if (!data.parent_commit_sha && preCommitSha) {
22049
22051
  data.parent_commit_sha = preCommitSha;
22052
+ } else if (data.parent_commit_sha) {
22053
+ if (!data.new_branch) {
22054
+ const date5 = import_dayjs.default().format("MMDDHHmm");
22055
+ data.new_branch = `refs/heads/${date5}`;
22056
+ }
22050
22057
  }
22051
22058
  const url3 = `${this.hackURL}/${repo}/-/git/commits`;
22052
22059
  const postData = {
@@ -43878,7 +43885,9 @@ function createOpenAICompatible(options) {
43878
43885
  // agent/modules/cnb-manager.ts
43879
43886
  var getConfig2 = async (opts) => {
43880
43887
  const kevisualEnv = useKey("KEVISUAL_ENV");
43881
- const baseUrl = kevisualEnv === "production" ? "https://kevisual.cn/api/router" : "https://kevisual.xiongxiao.me/api/router";
43888
+ const isCNB = useKey("CNB");
43889
+ let isProduction = kevisualEnv !== "development" || isCNB && !kevisualEnv;
43890
+ const baseUrl = isProduction ? "https://kevisual.cn/api/router" : "https://kevisual.xiongxiao.me/api/router";
43882
43891
  const res = await fetch(baseUrl, {
43883
43892
  method: "POST",
43884
43893
  body: JSON.stringify({
@@ -43924,6 +43933,8 @@ class CNBManager {
43924
43933
  if (token) {
43925
43934
  return this.addCNB({ username, token, cookie });
43926
43935
  }
43936
+ } else {
43937
+ console.error("获取 CNB 配置失败", username, res);
43927
43938
  }
43928
43939
  return null;
43929
43940
  }
@@ -57966,7 +57977,7 @@ app.route({
57966
57977
  }).addTo(app);
57967
57978
 
57968
57979
  // agent/routes/cnb-board/live/live-content.ts
57969
- var import_dayjs = __toESM(require_dayjs_min(), 1);
57980
+ var import_dayjs2 = __toESM(require_dayjs_min(), 1);
57970
57981
  import os2 from "node:os";
57971
57982
  import { execSync as execSync2 } from "node:child_process";
57972
57983
  var getLiveMdContent = (opts) => {
@@ -58180,8 +58191,8 @@ var createOSInfo = (more = false) => {
58180
58191
  description: "当前目录磁盘使用情况"
58181
58192
  });
58182
58193
  if (startTimer) {
58183
- const buildStartTime = import_dayjs.default(startTimer).format("YYYY-MM-DD HH:mm:ss");
58184
- const buildStartTimestamp = import_dayjs.default(startTimer).valueOf();
58194
+ const buildStartTime = import_dayjs2.default(startTimer).format("YYYY-MM-DD HH:mm:ss");
58195
+ const buildStartTimestamp = import_dayjs2.default(startTimer).valueOf();
58185
58196
  const buildUptime = Date.now() - buildStartTimestamp;
58186
58197
  const buildUptimeStr = formatUptime(Math.floor(buildUptime / 1000));
58187
58198
  const maxRunTime = useKey("CNB_PIPELINE_MAX_RUN_TIME") || 0;
@@ -58197,7 +58208,7 @@ var createOSInfo = (more = false) => {
58197
58208
  description: `构建已运行时间: ${buildUptimeStr}`
58198
58209
  });
58199
58210
  if (maxRunTime > 0) {
58200
- const now = import_dayjs.default();
58211
+ const now = import_dayjs2.default();
58201
58212
  const today4am = now.hour(4).minute(0).second(0).millisecond(0);
58202
58213
  let timeTo4 = today4am.valueOf() - now.valueOf();
58203
58214
  if (timeTo4 < 0) {
@@ -58751,7 +58762,7 @@ app.route({
58751
58762
  description: "清理我的cnb-manager记录",
58752
58763
  middleware: ["auth"]
58753
58764
  }).define(async (ctx) => {
58754
- const tokenUser = ctx.tokenUser;
58765
+ const tokenUser = ctx.state?.tokenUser;
58755
58766
  if (!tokenUser) {
58756
58767
  ctx.throw(401, "未授权");
58757
58768
  }
@@ -58770,7 +58781,8 @@ app.route({
58770
58781
  description: "获取我的cnb配置",
58771
58782
  middleware: ["auth"]
58772
58783
  }).define(async (ctx) => {
58773
- const username = ctx.tokenUser?.username;
58784
+ const tokenUser = ctx.state?.tokenUser;
58785
+ const username = tokenUser?.username;
58774
58786
  const token2 = ctx.query?.token;
58775
58787
  if (!username) {
58776
58788
  ctx.throw(400, "未授权");
package/dist/routes.d.ts CHANGED
@@ -282,6 +282,12 @@ declare class Repo extends CNBCore {
282
282
  createRepo(data: CreateRepoData): Promise<any>;
283
283
  deleteRepoCookie(repo: string): Promise<any>;
284
284
  deleteRepo(repo: string): Promise<any>;
285
+ /**
286
+ * 使用cookie创建提交,如果没有指定parent_commit_sha,则会自动获取最新的提交作为父提交
287
+ * @param repo
288
+ * @param data
289
+ * @returns
290
+ */
285
291
  createCommit(repo: string, data: CreateCommitData): Promise<any>;
286
292
  createBlobs(repo: string, data: {
287
293
  content: string;
package/dist/routes.js CHANGED
@@ -22012,6 +22012,8 @@ class KnowledgeBase extends CNBCore {
22012
22012
  }
22013
22013
 
22014
22014
  // src/repo/index.ts
22015
+ var import_dayjs = __toESM(require_dayjs_min(), 1);
22016
+
22015
22017
  class Repo extends CNBCore {
22016
22018
  constructor(options) {
22017
22019
  super(options);
@@ -22047,6 +22049,11 @@ class Repo extends CNBCore {
22047
22049
  const preCommitSha = commitList.length > 0 ? commitList[0].sha : undefined;
22048
22050
  if (!data.parent_commit_sha && preCommitSha) {
22049
22051
  data.parent_commit_sha = preCommitSha;
22052
+ } else if (data.parent_commit_sha) {
22053
+ if (!data.new_branch) {
22054
+ const date5 = import_dayjs.default().format("MMDDHHmm");
22055
+ data.new_branch = `refs/heads/${date5}`;
22056
+ }
22050
22057
  }
22051
22058
  const url3 = `${this.hackURL}/${repo}/-/git/commits`;
22052
22059
  const postData = {
@@ -43878,7 +43885,9 @@ function createOpenAICompatible(options) {
43878
43885
  // agent/modules/cnb-manager.ts
43879
43886
  var getConfig2 = async (opts) => {
43880
43887
  const kevisualEnv = useKey("KEVISUAL_ENV");
43881
- const baseUrl = kevisualEnv === "production" ? "https://kevisual.cn/api/router" : "https://kevisual.xiongxiao.me/api/router";
43888
+ const isCNB = useKey("CNB");
43889
+ let isProduction = kevisualEnv !== "development" || isCNB && !kevisualEnv;
43890
+ const baseUrl = isProduction ? "https://kevisual.cn/api/router" : "https://kevisual.xiongxiao.me/api/router";
43882
43891
  const res = await fetch(baseUrl, {
43883
43892
  method: "POST",
43884
43893
  body: JSON.stringify({
@@ -43924,6 +43933,8 @@ class CNBManager {
43924
43933
  if (token) {
43925
43934
  return this.addCNB({ username, token, cookie });
43926
43935
  }
43936
+ } else {
43937
+ console.error("获取 CNB 配置失败", username, res);
43927
43938
  }
43928
43939
  return null;
43929
43940
  }
@@ -57966,7 +57977,7 @@ app.route({
57966
57977
  }).addTo(app);
57967
57978
 
57968
57979
  // agent/routes/cnb-board/live/live-content.ts
57969
- var import_dayjs = __toESM(require_dayjs_min(), 1);
57980
+ var import_dayjs2 = __toESM(require_dayjs_min(), 1);
57970
57981
  import os2 from "node:os";
57971
57982
  import { execSync as execSync2 } from "node:child_process";
57972
57983
  var getLiveMdContent = (opts) => {
@@ -58180,8 +58191,8 @@ var createOSInfo = (more = false) => {
58180
58191
  description: "当前目录磁盘使用情况"
58181
58192
  });
58182
58193
  if (startTimer) {
58183
- const buildStartTime = import_dayjs.default(startTimer).format("YYYY-MM-DD HH:mm:ss");
58184
- const buildStartTimestamp = import_dayjs.default(startTimer).valueOf();
58194
+ const buildStartTime = import_dayjs2.default(startTimer).format("YYYY-MM-DD HH:mm:ss");
58195
+ const buildStartTimestamp = import_dayjs2.default(startTimer).valueOf();
58185
58196
  const buildUptime = Date.now() - buildStartTimestamp;
58186
58197
  const buildUptimeStr = formatUptime(Math.floor(buildUptime / 1000));
58187
58198
  const maxRunTime = useKey("CNB_PIPELINE_MAX_RUN_TIME") || 0;
@@ -58197,7 +58208,7 @@ var createOSInfo = (more = false) => {
58197
58208
  description: `构建已运行时间: ${buildUptimeStr}`
58198
58209
  });
58199
58210
  if (maxRunTime > 0) {
58200
- const now = import_dayjs.default();
58211
+ const now = import_dayjs2.default();
58201
58212
  const today4am = now.hour(4).minute(0).second(0).millisecond(0);
58202
58213
  let timeTo4 = today4am.valueOf() - now.valueOf();
58203
58214
  if (timeTo4 < 0) {
@@ -58751,7 +58762,7 @@ app.route({
58751
58762
  description: "清理我的cnb-manager记录",
58752
58763
  middleware: ["auth"]
58753
58764
  }).define(async (ctx) => {
58754
- const tokenUser = ctx.tokenUser;
58765
+ const tokenUser = ctx.state?.tokenUser;
58755
58766
  if (!tokenUser) {
58756
58767
  ctx.throw(401, "未授权");
58757
58768
  }
@@ -58770,7 +58781,8 @@ app.route({
58770
58781
  description: "获取我的cnb配置",
58771
58782
  middleware: ["auth"]
58772
58783
  }).define(async (ctx) => {
58773
- const username = ctx.tokenUser?.username;
58784
+ const tokenUser = ctx.state?.tokenUser;
58785
+ const username = tokenUser?.username;
58774
58786
  const token2 = ctx.query?.token;
58775
58787
  if (!username) {
58776
58788
  ctx.throw(400, "未授权");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/cnb",
3
- "version": "0.0.43",
3
+ "version": "0.0.45",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "basename": "/root/cnb",
@@ -17,8 +17,8 @@
17
17
  },
18
18
  "keywords": [],
19
19
  "bin": {
20
- "cnb": "./bin/index.js",
21
- "cloud": "./bin/index.js"
20
+ "cnb": "bin/index.js",
21
+ "cloud": "bin/index.js"
22
22
  },
23
23
  "files": [
24
24
  "dist",
@@ -74,4 +74,4 @@
74
74
  "./src/*": "./src/*",
75
75
  "./agent/*": "./agent/*"
76
76
  }
77
- }
77
+ }
package/readme.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # cnb.cool 能做什么
2
2
 
3
+ 所有的代码仓库,只基于一个准则 `group/repo`
3
4
  ## 简介
4
5
 
5
6
  纯粹调用api的模式去使用cnb.cool,自动化方案。
package/src/repo/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CNBCore, CNBCoreOptions, RequestOptions, Result } from "../cnb-core.ts";
2
-
2
+ import dayjs from "dayjs";
3
3
  export class Repo extends CNBCore {
4
4
  constructor(options: CNBCoreOptions) {
5
5
  super(options);
@@ -30,6 +30,12 @@ export class Repo extends CNBCore {
30
30
  const url = `/${repo}`;
31
31
  return this.delete({ url });
32
32
  }
33
+ /**
34
+ * 使用cookie创建提交,如果没有指定parent_commit_sha,则会自动获取最新的提交作为父提交
35
+ * @param repo
36
+ * @param data
37
+ * @returns
38
+ */
33
39
  async createCommit(repo: string, data: CreateCommitData): Promise<any> {
34
40
  const commitList = await this.getCommitList(repo, {
35
41
  page: 1,
@@ -41,6 +47,12 @@ export class Repo extends CNBCore {
41
47
  const preCommitSha = commitList.length > 0 ? commitList[0].sha : undefined;
42
48
  if (!data.parent_commit_sha && preCommitSha) {
43
49
  data.parent_commit_sha = preCommitSha;
50
+ } else if (data.parent_commit_sha) {
51
+ // 如果指定了parent_commi_sha;
52
+ if (!data.new_branch) {
53
+ const date = dayjs().format('MMDDHHmm');
54
+ data.new_branch = `refs/heads/${date}`;
55
+ }
44
56
  }
45
57
  const url = `${this.hackURL}/${repo}/-/git/commits`;
46
58
  const postData: CreateCommitData = {
@@ -52,6 +64,7 @@ export class Repo extends CNBCore {
52
64
  new_branch: data.new_branch || 'refs/heads/main',
53
65
  };
54
66
  if (!postData.parent_commit_sha) {
67
+ // 如果没有父提交sha,则说明是第一次提交,可以删除parent_commit_sha和base_branch字段
55
68
  delete postData.parent_commit_sha;
56
69
  delete postData.base_branch;
57
70
  }