Revert "feat(tg): 思考块改为可折叠引用块(与工具调用区分)"

This reverts commit 6d00225cc4.
This commit is contained in:
RRRosmontis
2026-09-17 11:39:18 +08:00
parent 6d00225cc4
commit 566932e0ae
4 changed files with 16 additions and 94 deletions
+3 -11
View File
@@ -75,10 +75,8 @@ const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const REASONING_QUOTE_MAX_CHARS = 800; const REASONING_QUOTE_MAX_CHARS = 800;
/** /**
* Assistant message → markdown for delivery. Reasoning (thinking) blocks are * Assistant message → markdown for delivery. Reasoning (thinking) blocks are
* kept as EXPANDABLE quotes (`**>`…`||` per Telegram's native markdown spec, * kept, one `> ` quote line each — Telegram renders them as the accent-bar
* `<blockquote expandable>` in HTML mode) so they stay collapsed on the phone * quote style the phone user expects for bash/thinking-style chatter.
* and visually distinct from tool-call quotes; ordinary quotes in assistant
* text remain plain blockquotes.
*/ */
function contentToText(content) { function contentToText(content) {
const parts = []; const parts = [];
@@ -92,13 +90,7 @@ function contentToText(content) {
continue; continue;
if (thinking.length > REASONING_QUOTE_MAX_CHARS) if (thinking.length > REASONING_QUOTE_MAX_CHARS)
thinking = `${thinking.slice(0, REASONING_QUOTE_MAX_CHARS)}…`; thinking = `${thinking.slice(0, REASONING_QUOTE_MAX_CHARS)}…`;
// `||` would open/close spoiler entities in native markdown — neutralize. parts.push(thinking.split('\n').map((line) => `> ${line}`).join('\n'));
const lines = thinking.replace(/\|\|/g, '||').split('\n');
const last = lines.length - 1;
parts.push([
'**>💭 思考过程',
...lines.map((line, i) => `> ${line}${i === last ? '||' : ''}`),
].join('\n'));
} }
} }
return parts.join('\n\n'); return parts.join('\n\n');
+5 -37
View File
@@ -12,54 +12,22 @@ function inlineToHtml(text) {
html = html.replace(/\*\*([^*\n]+)\*\*/g, '<b>$1</b>'); html = html.replace(/\*\*([^*\n]+)\*\*/g, '<b>$1</b>');
return html; return html;
} }
/** /** Convert `> …` line groups into `<blockquote>` (Telegram renders it with the accent-colored left bar). */
* Convert `> …` line groups into `<blockquote>` (Telegram renders it with the
* accent-colored left bar). The native-markdown expandable-quote form
* (`**>first line` … `last line||`) becomes `<blockquote expandable>` — used
* for thinking blocks so they stay collapsed and distinct from tool-call
* quotes (Telegram has no per-message quote color).
*/
const EXPANDABLE_OPEN = '**>';
function blocksToHtml(text) { function blocksToHtml(text) {
const lines = text.split('\n'); const lines = text.split('\n');
const out = []; const out = [];
let quote = []; let quote = [];
let expandable = false;
const flush = () => { const flush = () => {
if (quote.length === 0) if (quote.length === 0)
return; return;
const open = expandable ? '<blockquote expandable>' : '<blockquote>'; out.push(`<blockquote>${inlineToHtml(quote.join('\n'))}</blockquote>`);
out.push(`${open}${inlineToHtml(quote.join('\n'))}</blockquote>`);
quote = []; quote = [];
expandable = false;
}; };
for (const line of lines) { for (const line of lines) {
if (line.startsWith(EXPANDABLE_OPEN)) { if (line.startsWith('> '))
flush(); quote.push(line.slice(2));
expandable = true; else if (line === '>')
let content = line.slice(EXPANDABLE_OPEN.length);
if (content.endsWith('||')) {
quote.push(content.slice(0, -2));
flush();
}
else {
quote.push(content);
}
}
else if (line.startsWith('> ')) {
let content = line.slice(2);
let closed = false;
if (expandable && content.endsWith('||')) {
content = content.slice(0, -2);
closed = true;
}
quote.push(content);
if (closed)
flush();
}
else if (line === '>') {
quote.push(''); quote.push('');
}
else { else {
flush(); flush();
out.push(inlineToHtml(line)); out.push(inlineToHtml(line));
+3 -11
View File
@@ -210,10 +210,8 @@ const REASONING_QUOTE_MAX_CHARS = 800
/** /**
* Assistant message → markdown for delivery. Reasoning (thinking) blocks are * Assistant message → markdown for delivery. Reasoning (thinking) blocks are
* kept as EXPANDABLE quotes (`**>`…`||` per Telegram's native markdown spec, * kept, one `> ` quote line each — Telegram renders them as the accent-bar
* `<blockquote expandable>` in HTML mode) so they stay collapsed on the phone * quote style the phone user expects for bash/thinking-style chatter.
* and visually distinct from tool-call quotes; ordinary quotes in assistant
* text remain plain blockquotes.
*/ */
function contentToText(content: readonly ContentBlock[]): string { function contentToText(content: readonly ContentBlock[]): string {
const parts: string[] = [] const parts: string[] = []
@@ -225,13 +223,7 @@ function contentToText(content: readonly ContentBlock[]): string {
if (!thinking) continue if (!thinking) continue
if (thinking.length > REASONING_QUOTE_MAX_CHARS) if (thinking.length > REASONING_QUOTE_MAX_CHARS)
thinking = `${thinking.slice(0, REASONING_QUOTE_MAX_CHARS)}…` thinking = `${thinking.slice(0, REASONING_QUOTE_MAX_CHARS)}…`
// `||` would open/close spoiler entities in native markdown — neutralize. parts.push(thinking.split('\n').map((line) => `> ${line}`).join('\n'))
const lines = thinking.replace(/\|\|/g, '||').split('\n')
const last = lines.length - 1
parts.push([
'**>💭 思考过程',
...lines.map((line, i) => `> ${line}${i === last ? '||' : ''}`),
].join('\n'))
} }
} }
return parts.join('\n\n') return parts.join('\n\n')
+5 -35
View File
@@ -14,50 +14,20 @@ function inlineToHtml(text: string): string {
return html return html
} }
/** /** Convert `> …` line groups into `<blockquote>` (Telegram renders it with the accent-colored left bar). */
* Convert `> …` line groups into `<blockquote>` (Telegram renders it with the
* accent-colored left bar). The native-markdown expandable-quote form
* (`**>first line` … `last line||`) becomes `<blockquote expandable>` — used
* for thinking blocks so they stay collapsed and distinct from tool-call
* quotes (Telegram has no per-message quote color).
*/
const EXPANDABLE_OPEN = '**>'
function blocksToHtml(text: string): string { function blocksToHtml(text: string): string {
const lines = text.split('\n') const lines = text.split('\n')
const out: string[] = [] const out: string[] = []
let quote: string[] = [] let quote: string[] = []
let expandable = false
const flush = (): void => { const flush = (): void => {
if (quote.length === 0) return if (quote.length === 0) return
const open = expandable ? '<blockquote expandable>' : '<blockquote>' out.push(`<blockquote>${inlineToHtml(quote.join('\n'))}</blockquote>`)
out.push(`${open}${inlineToHtml(quote.join('\n'))}</blockquote>`)
quote = [] quote = []
expandable = false
} }
for (const line of lines) { for (const line of lines) {
if (line.startsWith(EXPANDABLE_OPEN)) { if (line.startsWith('> ')) quote.push(line.slice(2))
flush() else if (line === '>') quote.push('')
expandable = true else {
let content = line.slice(EXPANDABLE_OPEN.length)
if (content.endsWith('||')) {
quote.push(content.slice(0, -2))
flush()
} else {
quote.push(content)
}
} else if (line.startsWith('> ')) {
let content = line.slice(2)
let closed = false
if (expandable && content.endsWith('||')) {
content = content.slice(0, -2)
closed = true
}
quote.push(content)
if (closed) flush()
} else if (line === '>') {
quote.push('')
} else {
flush() flush()
out.push(inlineToHtml(line)) out.push(inlineToHtml(line))
} }