@git-ai/cli 1.0.2 → 1.0.3

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,72 +1,71 @@
1
- import Logger from "./Logger.mjs";
2
- import { config } from "./Storage.mjs";
3
-
4
- import { writeLogFile } from "./Log.mjs";
5
- /**
6
- * 退出进程
7
- */
8
- export const exitProcess = (code = 0, startTimestamp) => {
9
- writeLogFile();
10
- if (startTimestamp) {
11
- const endTimestamp = Date.now();
12
- const duration = endTimestamp - startTimestamp;
13
- const durationText = `${(duration / 1000).toFixed(3)} 秒`;
14
- const message = `本次执行指令${
15
- duration > 10000 ? "耗时" : "用时"
16
- }: ${durationText},程序退出...`;
17
-
18
- if (code === 0) {
19
- Logger.verbose(message);
20
- } else {
21
- Logger.verbose(message);
22
- }
23
- }
24
- process.exit(code);
25
- };
26
- export const createDeviceId = () => {
27
- const chars =
28
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
29
- const length = 64;
30
- let deviceId = "";
31
- for (let i = 0; i < length; i++) {
32
- deviceId += chars.charAt(Math.floor(Math.random() * chars.length));
33
- }
34
- return deviceId;
35
- };
36
- /**
37
- * 获取设备ID
38
- */
39
- export const getDeviceId = () => {
40
- return config.get("deviceId") || createDeviceId();
41
- };
42
-
43
- /**
44
- * 格式化 token 显示(隐藏中间部分)
45
- * @param {string} token - 单个或多个 token(逗号分隔)
46
- * @returns {string} 格式化后的 token 字符串
47
- */
48
- export const formatToken = (token) => {
49
- if (!token) return "";
50
-
51
- return token
52
- .split(",")
53
- .map((t) => {
54
- const len = t.length;
55
- if (len < 12) return `${t.slice(0, len < 5 ? 1 : 3)}...`;
56
- return `${t.slice(0, 5)}...${t.slice(-5)}`;
57
- })
58
- .join("、");
59
- };
60
- // 写个方法,传入 [string,string],随机取1个
61
- export const randomItem = (arr) => {
62
- return arr[Math.floor(Math.random() * arr.length)];
63
- };
64
- export const getOpenAiConfig = (key) => {
65
- const item = config.get(key) || "";
66
- const arr = item ? item.split(",") : [];
67
- return randomItem(arr) || "";
68
- };
69
- export const getRandomItem = (str) => {
70
- const arr = str ? str.split(",") : [];
71
- return randomItem(arr) || "";
72
- };
1
+ import Logger from './Logger.mjs';
2
+ import { config } from './Storage.mjs';
3
+
4
+ import { writeLogFile } from './Log.mjs';
5
+ /**
6
+ * 退出进程
7
+ */
8
+ export const exitProcess = (code = 0, startTimestamp) => {
9
+ writeLogFile();
10
+ if (startTimestamp) {
11
+ const endTimestamp = Date.now();
12
+ const duration = endTimestamp - startTimestamp;
13
+ const durationText = `${(duration / 1000).toFixed(3)} 秒`;
14
+ const message = `本次执行指令${
15
+ duration > 10000 ? '耗时' : '用时'
16
+ }: ${durationText},程序退出...`;
17
+
18
+ if (code === 0) {
19
+ Logger.verbose(message);
20
+ } else {
21
+ Logger.verbose(message);
22
+ }
23
+ }
24
+ process.exit(code);
25
+ };
26
+ export const createDeviceId = () => {
27
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
28
+ const length = 64;
29
+ let deviceId = '';
30
+ for (let i = 0; i < length; i++) {
31
+ deviceId += chars.charAt(Math.floor(Math.random() * chars.length));
32
+ }
33
+ return deviceId;
34
+ };
35
+ /**
36
+ * 获取设备ID
37
+ */
38
+ export const getDeviceId = () => {
39
+ return config.get('deviceId') || createDeviceId();
40
+ };
41
+
42
+ /**
43
+ * 格式化 token 显示(隐藏中间部分)
44
+ * @param {string} token - 单个或多个 token(逗号分隔)
45
+ * @returns {string} 格式化后的 token 字符串
46
+ */
47
+ export const formatToken = (token) => {
48
+ if (!token) return '';
49
+
50
+ return token
51
+ .split(',')
52
+ .map((t) => {
53
+ const len = t.length;
54
+ if (len < 12) return `${t.slice(0, len < 5 ? 1 : 3)}...`;
55
+ return `${t.slice(0, 5)}...${t.slice(-5)}`;
56
+ })
57
+ .join('、');
58
+ };
59
+ // 写个方法,传入 [string,string],随机取1个
60
+ export const randomItem = (arr) => {
61
+ return arr[Math.floor(Math.random() * arr.length)];
62
+ };
63
+ export const getOpenAiConfig = (key) => {
64
+ const item = config.get(key) || '';
65
+ const arr = item ? item.split(',') : [];
66
+ return randomItem(arr) || '';
67
+ };
68
+ export const getRandomItem = (str) => {
69
+ const arr = str ? str.split(',') : [];
70
+ return randomItem(arr) || '';
71
+ };