@ww_nero/mini-cli 1.0.83 → 1.0.86

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": "@ww_nero/mini-cli",
3
- "version": "1.0.83",
3
+ "version": "1.0.86",
4
4
  "description": "极简的 AI 命令行助手",
5
5
  "bin": {
6
6
  "mini": "bin/mini.js"
@@ -32,6 +32,8 @@
32
32
  "diff": "^5.2.0",
33
33
  "eventsource-parser": "^1.1.2",
34
34
  "gpt-tokenizer": "^2.9.0",
35
+ "marked": "^15.0.12",
36
+ "marked-terminal": "^7.3.0",
35
37
  "node-fetch": "^2.7.0",
36
38
  "openai": "^6.9.1"
37
39
  }
package/src/llm.js CHANGED
@@ -1,5 +1,36 @@
1
1
  const { makeRequestWithRetry, processStreamResponse } = require('./request');
2
2
 
3
+ const ensureValidArguments = (args) => {
4
+ if (typeof args !== 'string') return '{}';
5
+ try {
6
+ JSON.parse(args);
7
+ return args;
8
+ } catch (_) {
9
+ // 尝试截取第一个完整 JSON 对象
10
+ try {
11
+ const parts = args.split('}{');
12
+ if (parts.length > 1) {
13
+ const fixed = parts[0] + '}';
14
+ JSON.parse(fixed);
15
+ return fixed;
16
+ }
17
+ } catch (__) {
18
+ // ignore
19
+ }
20
+ return '{}';
21
+ }
22
+ };
23
+
24
+ const sanitizeToolCalls = (toolCalls) => {
25
+ return toolCalls.map((call) => ({
26
+ ...call,
27
+ function: {
28
+ ...call.function,
29
+ arguments: ensureValidArguments(call.function?.arguments)
30
+ }
31
+ }));
32
+ };
33
+
3
34
  const sanitizeMessages = (messages = []) => {
4
35
  return messages.map((message = {}) => {
5
36
  const role = message.role;
@@ -13,7 +44,7 @@ const sanitizeMessages = (messages = []) => {
13
44
  }
14
45
 
15
46
  if (role === 'assistant' && Array.isArray(message.tool_calls) && message.tool_calls.length > 0) {
16
- sanitized.tool_calls = message.tool_calls;
47
+ sanitized.tool_calls = sanitizeToolCalls(message.tool_calls);
17
48
  }
18
49
 
19
50
  if (message.reasoning_content) {
@@ -1,6 +1,22 @@
1
1
  const chalk = require('chalk');
2
+ const { marked } = require('marked');
3
+ const { markedTerminal } = require('marked-terminal');
2
4
  const { splitThinkContent, summarizeReasoning } = require('./think');
3
5
 
6
+ // 配置markdown终端渲染器
7
+ const renderer = markedTerminal({
8
+ heading: chalk.cyan.bold,
9
+ firstHeading: chalk.cyan.bold,
10
+ strong: chalk.bold,
11
+ em: chalk.italic,
12
+ blockquote: chalk.gray,
13
+ code: chalk.yellow,
14
+ codespan: chalk.yellow,
15
+ table: chalk.gray,
16
+ href: chalk.blue.underline
17
+ });
18
+ marked.use(renderer);
19
+
4
20
  const mergeReasoningContent = (...segments) => {
5
21
  const normalized = segments
6
22
  .map((segment) => (typeof segment === 'string' ? segment.trim() : ''))
@@ -22,7 +38,8 @@ const printAssistantContent = (text, ensureNewline) => {
22
38
  return;
23
39
  }
24
40
  ensureNewline();
25
- const output = chalk.white(text);
41
+ // 使用marked渲染markdown,生成带ANSI样式的终端输出
42
+ const output = marked(text);
26
43
  process.stdout.write(output);
27
44
  if (!text.endsWith('\n')) {
28
45
  process.stdout.write('\n');