@ww_nero/mini-cli 1.0.93 → 1.0.96
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 +1 -1
- package/src/chat.js +31 -4
package/package.json
CHANGED
package/src/chat.js
CHANGED
|
@@ -12,7 +12,7 @@ const { performCompactSummary } = require('./request');
|
|
|
12
12
|
const { toolSystemPrompt } = require('./prompt/tool');
|
|
13
13
|
const { createToolRuntime } = require('./tools');
|
|
14
14
|
const { renderToolCall } = require('./utils/renderer');
|
|
15
|
-
const { safeJsonParse } = require('./utils/helpers');
|
|
15
|
+
const { safeJsonParse, countLines } = require('./utils/helpers');
|
|
16
16
|
const { describeModel, createModelManager } = require('./utils/model');
|
|
17
17
|
const { SLASH_COMMANDS, createCommandHandler } = require('./utils/commands');
|
|
18
18
|
const { CLI_OPTIONS } = require('./utils/cliOptions');
|
|
@@ -172,6 +172,22 @@ const formatToolResultForDisplay = (text, maxLength = 100) => {
|
|
|
172
172
|
return normalized.length > maxLength ? 'Done' : normalized;
|
|
173
173
|
};
|
|
174
174
|
|
|
175
|
+
const getReadableErrorMessage = (error) => {
|
|
176
|
+
if (error && typeof error.message === 'string' && error.message.trim()) {
|
|
177
|
+
return error.message.trim();
|
|
178
|
+
}
|
|
179
|
+
if (typeof error === 'string' && error.trim()) {
|
|
180
|
+
return error.trim();
|
|
181
|
+
}
|
|
182
|
+
return '未知错误';
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const buildEmptyAssistantResponseNotice = (usage) => {
|
|
186
|
+
const usageText = formatUsageTokens(usage);
|
|
187
|
+
const usageSuffix = usageText ? `(${usageText})` : '';
|
|
188
|
+
return `本次请求已结束,但模型未返回可显示内容${usageSuffix}。可能是接口返回空响应、只返回了空白内容,或流式输出在正文前结束。请重试,必要时检查模型服务日志。`;
|
|
189
|
+
};
|
|
190
|
+
|
|
175
191
|
const indentToolResult = (text = '') => splitDisplayLines(text)
|
|
176
192
|
.map((line) => ` ${line}`)
|
|
177
193
|
.join('\n');
|
|
@@ -928,7 +944,8 @@ const startChatSession = async ({
|
|
|
928
944
|
onReasoningToken: handleReasoningChunk,
|
|
929
945
|
onUsage: updateLoadingPromptTokens,
|
|
930
946
|
onRetry: (retryCount, error) => {
|
|
931
|
-
const
|
|
947
|
+
const detailMessage = error ? getReadableErrorMessage(error) : '';
|
|
948
|
+
const detail = detailMessage ? `(${detailMessage})` : '';
|
|
932
949
|
process.stdout.write(`\n${chalk.yellow(`请求失败,${retryCount} 次重试中${detail}...`)}\n`);
|
|
933
950
|
}
|
|
934
951
|
});
|
|
@@ -1070,8 +1087,18 @@ const startChatSession = async ({
|
|
|
1070
1087
|
continue;
|
|
1071
1088
|
}
|
|
1072
1089
|
|
|
1073
|
-
conversationAdvanced = true;
|
|
1074
1090
|
const finalText = sanitizeContentWithThink(streamState.content, result.content);
|
|
1091
|
+
if (!mergedReasoning && !finalText) {
|
|
1092
|
+
if (messages[messages.length - 1] === userMessage) {
|
|
1093
|
+
messages.pop();
|
|
1094
|
+
persistHistorySafely();
|
|
1095
|
+
}
|
|
1096
|
+
ensureNewline();
|
|
1097
|
+
console.log(chalk.yellow(buildEmptyAssistantResponseNotice(result.usage)));
|
|
1098
|
+
break;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
conversationAdvanced = true;
|
|
1075
1102
|
renderAssistantOutput(mergedReasoning, finalText, ensureNewline);
|
|
1076
1103
|
const assistantMessage = buildHistoryAssistantMessage(
|
|
1077
1104
|
result.message,
|
|
@@ -1102,7 +1129,7 @@ const startChatSession = async ({
|
|
|
1102
1129
|
console.log(chalk.yellow('对话已取消。'));
|
|
1103
1130
|
}
|
|
1104
1131
|
} else {
|
|
1105
|
-
console.error(chalk.red(`请求失败: ${error
|
|
1132
|
+
console.error(chalk.red(`请求失败: ${getReadableErrorMessage(error)}`));
|
|
1106
1133
|
}
|
|
1107
1134
|
} finally {
|
|
1108
1135
|
clearLoadingPrompt();
|