quick-sh 1.0.4 → 1.0.5
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/CHANGELOG.md +15 -0
- package/package.json +19 -17
- package/{bin → src/bin}/cli.js +9 -3
- package/{lib → src/lib}/ai.js +32 -45
- package/{lib → src/lib}/i18n.js +19 -1
- package/{locales → src/locales}/en.json +2 -0
- package/{locales → src/locales}/ja.json +2 -0
- package/{locales → src/locales}/zh.json +2 -0
- /package/{lib → src/lib}/config.js +0 -0
- /package/{lib → src/lib}/executor.js +0 -0
- /package/{lib → src/lib}/help.js +0 -0
- /package/{lib → src/lib}/remote-manager.js +0 -0
- /package/{lib → src/lib}/script-manager.js +0 -0
- /package/{lib → src/lib}/utils.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
所有重要的更改都会记录在此文件中。
|
|
4
4
|
|
|
5
|
+
## [1.0.5] - 2025-06-18
|
|
6
|
+
|
|
7
|
+
### 更新内容
|
|
8
|
+
|
|
9
|
+
- refactor: src directory refactor, open ai downgrade to support node 14 (eeef017)
|
|
10
|
+
|
|
11
|
+
### 详细信息
|
|
12
|
+
- **更新人**: Young6118
|
|
13
|
+
- **更新时间**: 2025-06-18
|
|
14
|
+
- **提交数量**: 1
|
|
15
|
+
- **提交范围**: eeef017..eeef017
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
|
|
5
20
|
## [1.0.4] - 2025-06-18
|
|
6
21
|
|
|
7
22
|
### 更新内容
|
package/package.json
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quick-sh",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "A local script management tool for quick execution of JavaScript and Shell scripts with alias support",
|
|
5
|
-
"main": "lib/script-manager.js",
|
|
5
|
+
"main": "src/lib/script-manager.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"q": "bin/cli.js"
|
|
7
|
+
"q": "src/bin/cli.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
|
-
"bin/",
|
|
11
|
-
"lib/",
|
|
10
|
+
"src/bin/",
|
|
11
|
+
"src/lib/",
|
|
12
12
|
"README.md",
|
|
13
13
|
"LICENSE",
|
|
14
|
-
"locales/"
|
|
14
|
+
"src/locales/"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"test": "node test/run-all.js",
|
|
18
|
-
"test:legacy": "node test/test.js",
|
|
19
|
-
"test:basic": "node test/basic.test.js",
|
|
20
|
-
"test:script": "node test/script-execution.test.js",
|
|
21
|
-
"test:alias": "node test/alias.test.js",
|
|
22
|
-
"test:error": "node test/error-handling.test.js",
|
|
23
|
-
"test:config": "node test/config.test.js",
|
|
24
|
-
"test:
|
|
17
|
+
"test": "node src/test/run-all.js",
|
|
18
|
+
"test:legacy": "node src/test/test.js",
|
|
19
|
+
"test:basic": "node src/test/basic.test.js",
|
|
20
|
+
"test:script": "node src/test/script-execution.test.js",
|
|
21
|
+
"test:alias": "node src/test/alias.test.js",
|
|
22
|
+
"test:error": "node src/test/error-handling.test.js",
|
|
23
|
+
"test:config": "node src/test/config.test.js",
|
|
24
|
+
"test:ai": "node src/test/ai.test.js",
|
|
25
|
+
"test:help": "node src/test/run-all.js --help",
|
|
25
26
|
"test:manual": "echo \"Run manual tests with: q test-args, q test-args.sh, q test-dir\"",
|
|
26
27
|
"prepublishOnly": "npm test"
|
|
27
28
|
},
|
|
@@ -53,13 +54,14 @@
|
|
|
53
54
|
},
|
|
54
55
|
"dependencies": {
|
|
55
56
|
"commander": "^9.0.0",
|
|
56
|
-
"fs-extra": "^11.0.0"
|
|
57
|
+
"fs-extra": "^11.0.0",
|
|
58
|
+
"openai": "^3.3.0"
|
|
57
59
|
},
|
|
58
60
|
"devDependencies": {},
|
|
59
61
|
"preferGlobal": true,
|
|
60
62
|
"directories": {
|
|
61
63
|
"example": "examples",
|
|
62
|
-
"lib": "lib",
|
|
63
|
-
"test": "test"
|
|
64
|
+
"lib": "src/lib",
|
|
65
|
+
"test": "src/test"
|
|
64
66
|
}
|
|
65
67
|
}
|
package/{bin → src/bin}/cli.js
RENAMED
|
@@ -14,11 +14,17 @@ const {
|
|
|
14
14
|
removeRemoteScript,
|
|
15
15
|
SOURCE_TYPES
|
|
16
16
|
} = require('../lib/remote-manager');
|
|
17
|
-
const { initI18n } = require('../lib/i18n');
|
|
17
|
+
const { initI18n, forceReinitI18n } = require('../lib/i18n');
|
|
18
|
+
const packageJson = require('../../package.json');
|
|
18
19
|
|
|
19
20
|
// 初始化国际化系统
|
|
20
21
|
(async () => {
|
|
21
|
-
|
|
22
|
+
// 如果在测试环境中,强制重新初始化
|
|
23
|
+
if (process.env.QUICK_SH_TEST_LANG) {
|
|
24
|
+
await forceReinitI18n();
|
|
25
|
+
} else {
|
|
26
|
+
await initI18n();
|
|
27
|
+
}
|
|
22
28
|
|
|
23
29
|
// 自定义命令处理 - 在 commander.js 解析之前拦截
|
|
24
30
|
const args = process.argv.slice(2);
|
|
@@ -175,7 +181,7 @@ if (args.length > 0) {
|
|
|
175
181
|
program
|
|
176
182
|
.name('q')
|
|
177
183
|
.description('quick sh - Local script management tool')
|
|
178
|
-
.version(
|
|
184
|
+
.version(packageJson.version);
|
|
179
185
|
|
|
180
186
|
// 默认命令:执行脚本
|
|
181
187
|
program
|
package/{lib → src/lib}/ai.js
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const readline = require('readline');
|
|
2
|
-
const
|
|
2
|
+
const { Configuration, OpenAIApi } = require('openai');
|
|
3
3
|
const { t } = require('./i18n');
|
|
4
4
|
const { readConfig, writeConfig } = require('./config');
|
|
5
5
|
|
|
@@ -511,55 +511,42 @@ async function handleUserInput(input, model, promptCallback) {
|
|
|
511
511
|
}
|
|
512
512
|
|
|
513
513
|
// 调用AI API
|
|
514
|
-
function callAI(messages, model) {
|
|
515
|
-
|
|
516
|
-
|
|
514
|
+
async function callAI(messages, model) {
|
|
515
|
+
try {
|
|
516
|
+
// 构建基础URL
|
|
517
|
+
let basePath = model.apiUrl;
|
|
518
|
+
if (!basePath.startsWith('http://') && !basePath.startsWith('https://')) {
|
|
519
|
+
basePath = `https://${basePath}`;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// 创建 OpenAI 配置
|
|
523
|
+
const configuration = new Configuration({
|
|
524
|
+
apiKey: model.apiKey,
|
|
525
|
+
basePath: basePath,
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
// 创建 OpenAI API 实例
|
|
529
|
+
const openai = new OpenAIApi(configuration);
|
|
530
|
+
|
|
531
|
+
// 调用 chat completions API
|
|
532
|
+
const response = await openai.createChatCompletion({
|
|
517
533
|
model: model.model,
|
|
518
534
|
messages: messages,
|
|
519
535
|
max_tokens: model.maxTokens,
|
|
520
|
-
temperature: model.temperature
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
const options = {
|
|
524
|
-
hostname: model.apiUrl,
|
|
525
|
-
port: 443,
|
|
526
|
-
path: model.apiPath,
|
|
527
|
-
method: 'POST',
|
|
528
|
-
headers: {
|
|
529
|
-
'Content-Type': 'application/json',
|
|
530
|
-
'Authorization': `Bearer ${model.apiKey}`,
|
|
531
|
-
'Content-Length': Buffer.byteLength(postData)
|
|
532
|
-
}
|
|
533
|
-
};
|
|
534
|
-
|
|
535
|
-
const req = https.request(options, (res) => {
|
|
536
|
-
let data = '';
|
|
537
|
-
|
|
538
|
-
res.on('data', (chunk) => {
|
|
539
|
-
data += chunk;
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
res.on('end', () => {
|
|
543
|
-
try {
|
|
544
|
-
const response = JSON.parse(data);
|
|
545
|
-
if (response.error) {
|
|
546
|
-
reject(new Error(response.error.message));
|
|
547
|
-
} else {
|
|
548
|
-
resolve(response);
|
|
549
|
-
}
|
|
550
|
-
} catch (error) {
|
|
551
|
-
reject(new Error(t('ai.parseError')));
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
req.on('error', (error) => {
|
|
557
|
-
reject(error);
|
|
536
|
+
temperature: model.temperature,
|
|
558
537
|
});
|
|
559
538
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
539
|
+
return response.data;
|
|
540
|
+
} catch (error) {
|
|
541
|
+
// 处理不同类型的错误
|
|
542
|
+
if (error.code === 'ENOTFOUND') {
|
|
543
|
+
throw new Error(`${t('ai.connectionError')}: ${error.message}`);
|
|
544
|
+
} else if (error.response && error.response.status) {
|
|
545
|
+
throw new Error(`${t('ai.apiError')}: ${error.response.status} - ${error.response.statusText}`);
|
|
546
|
+
} else {
|
|
547
|
+
throw new Error(`${t('ai.error', { error: error.message })}`);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
563
550
|
}
|
|
564
551
|
|
|
565
552
|
// 显示聊天帮助
|
package/{lib → src/lib}/i18n.js
RENAMED
|
@@ -22,6 +22,11 @@ let translations = {};
|
|
|
22
22
|
// 检测系统语言
|
|
23
23
|
function detectSystemLanguage() {
|
|
24
24
|
try {
|
|
25
|
+
// 检查是否在测试环境中
|
|
26
|
+
if (process.env.QUICK_SH_TEST_LANG) {
|
|
27
|
+
return process.env.QUICK_SH_TEST_LANG;
|
|
28
|
+
}
|
|
29
|
+
|
|
25
30
|
// 获取系统语言环境
|
|
26
31
|
const locale = process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || process.env.LANGUAGE || 'en_US';
|
|
27
32
|
|
|
@@ -49,6 +54,11 @@ async function loadLanguage(lang = null) {
|
|
|
49
54
|
try {
|
|
50
55
|
let targetLang = lang;
|
|
51
56
|
|
|
57
|
+
// 在测试环境中,优先使用测试语言设置
|
|
58
|
+
if (!targetLang && process.env.QUICK_SH_TEST_LANG) {
|
|
59
|
+
targetLang = process.env.QUICK_SH_TEST_LANG;
|
|
60
|
+
}
|
|
61
|
+
|
|
52
62
|
// 如果没有指定语言,先尝试获取用户设置的语言
|
|
53
63
|
if (!targetLang) {
|
|
54
64
|
try {
|
|
@@ -143,11 +153,19 @@ async function initI18n() {
|
|
|
143
153
|
await loadLanguage();
|
|
144
154
|
}
|
|
145
155
|
|
|
156
|
+
// 强制重新初始化(用于测试)
|
|
157
|
+
async function forceReinitI18n() {
|
|
158
|
+
currentLanguage = DEFAULT_LANG;
|
|
159
|
+
translations = {};
|
|
160
|
+
await loadLanguage();
|
|
161
|
+
}
|
|
162
|
+
|
|
146
163
|
module.exports = {
|
|
147
164
|
t,
|
|
148
165
|
getCurrentLanguage,
|
|
149
166
|
getSupportedLanguages,
|
|
150
167
|
setLanguage,
|
|
151
168
|
initI18n,
|
|
152
|
-
detectSystemLanguage
|
|
169
|
+
detectSystemLanguage,
|
|
170
|
+
forceReinitI18n
|
|
153
171
|
};
|
|
@@ -241,6 +241,8 @@
|
|
|
241
241
|
"noResponse": "No response from AI",
|
|
242
242
|
"error": "Error: {{error}}",
|
|
243
243
|
"parseError": "Failed to parse API response",
|
|
244
|
+
"connectionError": "Connection Error",
|
|
245
|
+
"apiError": "API Error",
|
|
244
246
|
"chatHelp": "AI Chat Help",
|
|
245
247
|
"justTypeMessage": "Just type your message and press Enter to chat with AI",
|
|
246
248
|
"currentModelConfig": "Current Model Configuration",
|
|
@@ -241,6 +241,8 @@
|
|
|
241
241
|
"noResponse": "AI からの応答がありません",
|
|
242
242
|
"error": "エラー: {{error}}",
|
|
243
243
|
"parseError": "API レスポンスの解析に失敗しました",
|
|
244
|
+
"connectionError": "接続エラー",
|
|
245
|
+
"apiError": "API エラー",
|
|
244
246
|
"chatHelp": "AI チャットヘルプ",
|
|
245
247
|
"justTypeMessage": "メッセージを入力してエンターを押すだけで AI とチャットできます",
|
|
246
248
|
"currentModelConfig": "現在のモデル設定",
|
|
@@ -241,6 +241,8 @@
|
|
|
241
241
|
"noResponse": "AI 没有响应",
|
|
242
242
|
"error": "错误: {{error}}",
|
|
243
243
|
"parseError": "解析 API 响应失败",
|
|
244
|
+
"connectionError": "连接错误",
|
|
245
|
+
"apiError": "API 错误",
|
|
244
246
|
"chatHelp": "AI 聊天帮助",
|
|
245
247
|
"justTypeMessage": "只需输入消息然后按回车即可与 AI 聊天",
|
|
246
248
|
"currentModelConfig": "当前模型配置",
|
|
File without changes
|
|
File without changes
|
/package/{lib → src/lib}/help.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|