@kevisual/cnb 0.0.69 → 0.0.71

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.69",
3
+ "version": "0.0.71",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "basename": "/root/cnb",
@@ -33,19 +33,19 @@
33
33
  "packageManager": "pnpm@10.33.0",
34
34
  "type": "module",
35
35
  "devDependencies": {
36
- "@ai-sdk/openai-compatible": "^2.0.38",
36
+ "@ai-sdk/openai-compatible": "^2.0.41",
37
37
  "@kevisual/ai": "^0.0.30",
38
- "@kevisual/api": "^0.0.66",
38
+ "@kevisual/api": "^0.0.67",
39
39
  "@kevisual/code-builder": "^0.0.7",
40
40
  "@kevisual/context": "^0.0.8",
41
41
  "@kevisual/dts": "^0.0.4",
42
42
  "@kevisual/remote-app": "^0.0.7",
43
- "@kevisual/types": "^0.0.12",
44
- "@opencode-ai/plugin": "^1.3.17",
43
+ "@kevisual/types": "^0.0.14",
44
+ "@opencode-ai/plugin": "^1.4.3",
45
45
  "@types/bun": "^1.3.11",
46
- "@types/node": "^25.5.2",
46
+ "@types/node": "^25.6.0",
47
47
  "@types/ws": "^8.18.1",
48
- "ai": "^6.0.146",
48
+ "ai": "^6.0.156",
49
49
  "commander": "^14.0.3",
50
50
  "dayjs": "^1.11.20",
51
51
  "dotenv": "^17.4.1",
@@ -62,7 +62,7 @@
62
62
  "@kevisual/query": "^0.0.55",
63
63
  "@kevisual/router": "^0.2.5",
64
64
  "@kevisual/use-config": "^1.0.30",
65
- "@opencode-ai/sdk": "^1.3.17",
65
+ "@opencode-ai/sdk": "^1.4.3",
66
66
  "es-toolkit": "^1.45.1",
67
67
  "form-data": "^4.0.5",
68
68
  "nanoid": "^5.1.7",
@@ -76,6 +76,7 @@
76
76
  "./keep.ts": "./src/keep.ts",
77
77
  "./keep-file-live.ts": "./src/workspace/keep-file-live.ts",
78
78
  "./routes": "./dist/routes.js",
79
+ "./download.ts": "./src/repo/download.ts",
79
80
  "./src/*": "./src/*",
80
81
  "./agent/*": "./agent/*"
81
82
  }
package/src/cnb-git.ts ADDED
@@ -0,0 +1 @@
1
+ // https://rest2git.kevisuasl.cn/
@@ -0,0 +1,46 @@
1
+ type DownloadFn = (url: string, opts?: { headers?: any, hash?: string, token?: string }) => Promise<{ code: number; buffer: Buffer | null }>
2
+
3
+ /**
4
+ * 下载文件内容,使用CNB API,支持文件未修改时返回304状态码
5
+ * @param url https://api.cnb.cool/${REPO}/-/git/contents/${FILE_PATH}
6
+ * @param opts
7
+ * @returns
8
+ */
9
+ export const downloadByCNBApi: DownloadFn = async (url, opts) => {
10
+ const hash = opts?.hash;
11
+ const headers = opts?.token ? { Authorization: `${opts.token}` } : {};
12
+ const res = await fetch(url, {
13
+ headers: {
14
+ Accept: "application/vnd.cnb.api+json",
15
+ ...headers,
16
+ ...opts?.headers
17
+ }
18
+ });
19
+ type CNBResponse = {
20
+ type?: 'blob' | 'file' | 'dir';
21
+ size?: number;
22
+ path: string;
23
+ name: string;
24
+ sha?: string;
25
+ encoding?: string;
26
+ content?: string;
27
+ }
28
+ let resJson: CNBResponse;
29
+ try {
30
+ resJson = await res.json() as CNBResponse;
31
+ } catch (e) {
32
+ console.error(`下载失败 ${url}: ${res.statusText}`, e);
33
+ return { code: res.status, buffer: null };
34
+ }
35
+ if (res.ok && resJson.type === 'blob' && resJson.encoding === 'base64' && resJson.content) {
36
+ if (hash && resJson.sha === hash) {
37
+ // 文件未修改,跳过下载
38
+ return { code: 304, buffer: null };
39
+ }
40
+ const buffer = Buffer.from(resJson.content, 'base64');
41
+ return { code: 200, buffer };
42
+ } else {
43
+ console.error(`下载失败 ${url}: ${res.statusText}`, resJson);
44
+ return { code: res.status, buffer: null };
45
+ }
46
+ }
package/src/repo/index.ts CHANGED
@@ -90,16 +90,16 @@ export class Repo extends CNBCore {
90
90
  const url = `/${repo}/-/upload/files`
91
91
  return this.post({ url, data });
92
92
  }
93
- async getLastCommit(repo: string, opts?: RequestOptions): Promise<Result<CommitInfo>> {
93
+ async getLastCommit(repo: string, opts?: RequestOptions): Promise<Result<CommitInfo| null>> {
94
94
  const res = await this.getCommitList(repo, { page: 1, page_size: 1 }, opts);
95
95
  let commitList: CommitInfo[] = [];
96
96
  if (res.code === 200) {
97
- commitList = res.data;
97
+ commitList = res.data!;
98
98
  }
99
99
  return {
100
100
  code: res.code,
101
101
  message: res.message,
102
- data: commitList.length > 0 ? commitList[0] : null,
102
+ data: commitList.length > 0 ? commitList[0]! : null,
103
103
  }
104
104
  }
105
105
  getCommitList(repo: string, params?: { author?: string, commiter?: string, page?: number, page_size?: number, sha?: string, since?: string, until?: string }, opts?: RequestOptions): Promise<Result<CommitInfo[]>> {
package/dist/a/a.txt DELETED
@@ -1 +0,0 @@
1
- abc