foliko 1.1.57 → 1.1.59
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/cli/src/ui/chat-ui.js
CHANGED
|
@@ -449,7 +449,7 @@ class ChatUI {
|
|
|
449
449
|
}
|
|
450
450
|
setTimeout(() => {
|
|
451
451
|
this.tooler.hide();
|
|
452
|
-
this.create_message(`${colored('[提示]', CYAN)}
|
|
452
|
+
this.create_message(`${colored('[提示]', CYAN)} 上下文已压缩`,chalk.dim('● '))
|
|
453
453
|
this.tui.requestRender();
|
|
454
454
|
}, 2000);
|
|
455
455
|
}).catch(err => {
|
|
@@ -94,29 +94,40 @@ function renderInline(text) {
|
|
|
94
94
|
return result;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
function renderThink(line, state = { inThink: false },thinking) {
|
|
97
|
+
function renderThink(line, state = { inThink: false }, thinking) {
|
|
98
|
+
// 处理只有开始标签的情况(line = "<think>" 这样单独一行)
|
|
99
|
+
// 这种情况在流式输出时很常见
|
|
100
|
+
if (line === '<think>' || line === '<think>\n') {
|
|
101
|
+
state.inThink = true;
|
|
102
|
+
return STYLES.think.prefix + line;
|
|
103
|
+
}
|
|
104
|
+
|
|
98
105
|
let result = line;
|
|
99
106
|
|
|
100
107
|
// 匹配 <think>...</think> 以及可能的跨行情况
|
|
101
108
|
result = result.replace(/<think>([\s\S]*?)<\/think>/g, (match, content) => {
|
|
102
|
-
const prefix=result.indexOf('<think>')>0?'\n':""
|
|
103
|
-
return prefix+STYLES.think.prefix + match + STYLES.think.suffix;
|
|
109
|
+
const prefix = result.indexOf('<think>') > 0 ? '\n' : "";
|
|
110
|
+
return prefix + STYLES.think.prefix + match + STYLES.think.suffix;
|
|
104
111
|
});
|
|
105
112
|
|
|
106
113
|
// 处理未闭合的 think 标签 - 更新状态
|
|
107
|
-
if (result.includes('<think>')) {
|
|
114
|
+
if (result.includes('<think>') && !result.includes('</think>')) {
|
|
108
115
|
state.inThink = true;
|
|
109
116
|
}
|
|
110
117
|
if (result.includes('</think>')) {
|
|
111
118
|
state.inThink = false;
|
|
119
|
+
// 如果只有 </think> 标签(没有开始标签)
|
|
120
|
+
if (!result.includes('<think>')) {
|
|
121
|
+
return STYLES.think.prefix + line + STYLES.think.suffix;
|
|
122
|
+
}
|
|
112
123
|
}
|
|
113
124
|
|
|
114
125
|
// 处理未闭合的 think 标签(开始但没结束)
|
|
115
126
|
if (state.inThink && !result.includes('<think>')) {
|
|
116
|
-
result = STYLES.think.prefix + result;
|
|
127
|
+
result = STYLES.think.prefix + result + STYLES.think.suffix;
|
|
117
128
|
}
|
|
118
129
|
|
|
119
|
-
return thinking?result:renderInline(result);
|
|
130
|
+
return thinking ? result : renderInline(result);
|
|
120
131
|
}
|
|
121
132
|
|
|
122
133
|
/**
|
|
@@ -157,6 +168,11 @@ function renderLine(line, state = { inThink: false, inCodeBlock: false },thinkin
|
|
|
157
168
|
return result;
|
|
158
169
|
}
|
|
159
170
|
|
|
171
|
+
// 如果是 continuation 行(在思考块中但没有思考标签)
|
|
172
|
+
if (state.inThink && !line.includes('<think>') && !line.includes('</think>')) {
|
|
173
|
+
return STYLES.think.prefix + leadingNL + renderThink(line, state, thinking) + trailingNL + STYLES.think.suffix;
|
|
174
|
+
}
|
|
175
|
+
|
|
160
176
|
// 标题
|
|
161
177
|
if (line.startsWith('### ')) {
|
|
162
178
|
return `${STYLES.h3.prefix}${renderInline(line.substring(4))}${STYLES.h3.suffix}`;
|