quick-sh 1.0.6 → 1.0.7
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 +2 -2
- package/src/lib/ai.js +37 -17
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
所有重要的更改都会记录在此文件中。
|
|
4
4
|
|
|
5
|
+
## [1.0.7] - 2025-06-18
|
|
6
|
+
|
|
7
|
+
### 更新内容
|
|
8
|
+
|
|
9
|
+
- fix: remove openai, use axios (e8ad16f)
|
|
10
|
+
|
|
11
|
+
### 详细信息
|
|
12
|
+
- **更新人**: Young6118
|
|
13
|
+
- **更新时间**: 2025-06-18
|
|
14
|
+
- **提交数量**: 1
|
|
15
|
+
- **提交范围**: e8ad16f..e8ad16f
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
|
|
5
20
|
## [1.0.6] - 2025-06-18
|
|
6
21
|
|
|
7
22
|
### 更新内容
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quick-sh",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "A local script management tool for quick execution of JavaScript and Shell scripts with alias support",
|
|
5
5
|
"main": "src/lib/script-manager.js",
|
|
6
6
|
"bin": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"commander": "^9.0.0",
|
|
57
57
|
"fs-extra": "^11.0.0",
|
|
58
|
-
"
|
|
58
|
+
"axios": "^1.6.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {},
|
|
61
61
|
"preferGlobal": true,
|
package/src/lib/ai.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const readline = require('readline');
|
|
2
|
-
const
|
|
2
|
+
const axios = require('axios');
|
|
3
3
|
const { t } = require('./i18n');
|
|
4
4
|
const { readConfig, writeConfig } = require('./config');
|
|
5
5
|
|
|
@@ -513,36 +513,56 @@ async function handleUserInput(input, model, promptCallback) {
|
|
|
513
513
|
// 调用AI API
|
|
514
514
|
async function callAI(messages, model) {
|
|
515
515
|
try {
|
|
516
|
-
//
|
|
517
|
-
let
|
|
518
|
-
if (!
|
|
519
|
-
|
|
516
|
+
// 构建完整的API URL
|
|
517
|
+
let baseUrl = model.apiUrl;
|
|
518
|
+
if (!baseUrl.startsWith('http://') && !baseUrl.startsWith('https://')) {
|
|
519
|
+
baseUrl = `https://${baseUrl}`;
|
|
520
520
|
}
|
|
521
521
|
|
|
522
|
-
|
|
523
|
-
const configuration = new Configuration({
|
|
524
|
-
apiKey: model.apiKey,
|
|
525
|
-
basePath: basePath,
|
|
526
|
-
});
|
|
522
|
+
const apiUrl = `${baseUrl}${model.apiPath}`;
|
|
527
523
|
|
|
528
|
-
//
|
|
529
|
-
const
|
|
530
|
-
|
|
531
|
-
// 调用 chat completions API
|
|
532
|
-
const response = await openai.createChatCompletion({
|
|
524
|
+
// 构建请求payload
|
|
525
|
+
const payload = {
|
|
533
526
|
model: model.model,
|
|
534
527
|
messages: messages,
|
|
535
528
|
max_tokens: model.maxTokens,
|
|
536
529
|
temperature: model.temperature,
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
// 构建请求headers
|
|
533
|
+
const headers = {
|
|
534
|
+
'Content-Type': 'application/json',
|
|
535
|
+
'Authorization': `Bearer ${model.apiKey}`
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
// 发送HTTP请求
|
|
539
|
+
console.log(111, apiUrl, payload, headers)
|
|
540
|
+
const response = await axios.post(apiUrl, payload, {
|
|
541
|
+
headers: headers,
|
|
542
|
+
timeout: 30000 // 30秒超时
|
|
537
543
|
});
|
|
538
544
|
|
|
539
545
|
return response.data;
|
|
540
546
|
} catch (error) {
|
|
541
547
|
// 处理不同类型的错误
|
|
542
|
-
if (error.code === 'ENOTFOUND') {
|
|
548
|
+
if (error.code === 'ENOTFOUND' || error.code === 'ECONNREFUSED') {
|
|
543
549
|
throw new Error(`${t('ai.connectionError')}: ${error.message}`);
|
|
544
550
|
} else if (error.response && error.response.status) {
|
|
545
|
-
|
|
551
|
+
const status = error.response.status;
|
|
552
|
+
const statusText = error.response.statusText;
|
|
553
|
+
const errorData = error.response.data;
|
|
554
|
+
let errorMessage = `HTTP ${status}: ${statusText}`;
|
|
555
|
+
|
|
556
|
+
// 尝试获取更详细的错误信息
|
|
557
|
+
if (errorData && errorData.error) {
|
|
558
|
+
if (typeof errorData.error === 'string') {
|
|
559
|
+
errorMessage += ` - ${errorData.error}`;
|
|
560
|
+
} else if (errorData.error.message) {
|
|
561
|
+
errorMessage += ` - ${errorData.error.message}`;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
throw new Error(`${t('ai.apiError')}: ${errorMessage}`);
|
|
546
566
|
} else {
|
|
547
567
|
throw new Error(`${t('ai.error', { error: error.message })}`);
|
|
548
568
|
}
|