dsh-tg-bridge 1.9.2 → 1.9.3
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/README.md +9 -5
- package/bridge.mjs +9 -1
- package/package.json +1 -1
- package/panel.mjs +23 -8
package/README.md
CHANGED
|
@@ -264,13 +264,17 @@ Two things land in the same progress message, and neither sends a chat message o
|
|
|
264
264
|
**The model's reasoning.** Every `thinking` block the CLI commits is folded into one
|
|
265
265
|
Telegram `<blockquote expandable>`: collapsed it is a single line, tapped it opens the whole
|
|
266
266
|
trail of the turn, and it stays there after the turn ends — the same way the desktop app shows
|
|
267
|
-
a reasoning section you can expand. The block is
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
267
|
+
a reasoning section you can expand. The block is written once, in the final edit of the turn,
|
|
268
|
+
and never touched again: Telegram re-collapses an expanded block on every edit of its message,
|
|
269
|
+
which used to yank the chat away from a half-read paragraph. While the turn runs the message
|
|
270
|
+
only gets a counter (`🧠 Размышления · 4821`) and the last three steps, so the live edits stay
|
|
271
|
+
short. Escaped, and trimmed to its tail when a turn thinks longer than a message can hold; the
|
|
272
|
+
panel never exceeds one message. A cut block says `… · /thoughts`, which returns the whole
|
|
273
|
+
text. If the API refuses the markup, the same content is retried as plain text.
|
|
271
274
|
|
|
272
275
|
**The steps.** Three calls fit inline. A turn that makes more moves its complete step list into
|
|
273
|
-
a second collapsed block, so "what did it actually run" is one
|
|
276
|
+
a second collapsed block, added in that same final edit, so "what did it actually run" is one
|
|
277
|
+
tap away instead of a count.
|
|
274
278
|
|
|
275
279
|
**The agent's own notes.** The agent can add a short decision trail:
|
|
276
280
|
|
package/bridge.mjs
CHANGED
|
@@ -1026,8 +1026,15 @@ async function startProgress(chatId, threadId, lang = 'ru') {
|
|
|
1026
1026
|
log(`progress message failed: ${error.message}`);
|
|
1027
1027
|
}
|
|
1028
1028
|
|
|
1029
|
+
let lastView = '';
|
|
1029
1030
|
const edit = async (text, keyboard = undefined, view = null) => {
|
|
1030
1031
|
if (!messageId) return;
|
|
1032
|
+
// Re-sending identical text counts as an edit on the phone (the block
|
|
1033
|
+
// collapses and the list re-lays-out), so a no-op must not reach Telegram.
|
|
1034
|
+
if (view && keyboard === undefined && view.html === lastView) {
|
|
1035
|
+
dirty = false;
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1031
1038
|
const payload = {
|
|
1032
1039
|
chat_id: chatId,
|
|
1033
1040
|
message_id: messageId,
|
|
@@ -1042,6 +1049,7 @@ async function startProgress(chatId, threadId, lang = 'ru') {
|
|
|
1042
1049
|
if (keyboard !== undefined) body.reply_markup = keyboard ?? { inline_keyboard: [] };
|
|
1043
1050
|
await tg('editMessageText', body);
|
|
1044
1051
|
}
|
|
1052
|
+
lastView = view ? view.html : text;
|
|
1045
1053
|
lastEdit = Date.now();
|
|
1046
1054
|
} catch (error) {
|
|
1047
1055
|
// "message is not modified" and rate limits are expected: ignore quietly.
|
|
@@ -1057,7 +1065,7 @@ async function startProgress(chatId, threadId, lang = 'ru') {
|
|
|
1057
1065
|
if (!dirty) return;
|
|
1058
1066
|
dirty = false;
|
|
1059
1067
|
await edit('', undefined, panel());
|
|
1060
|
-
},
|
|
1068
|
+
}, 5000);
|
|
1061
1069
|
timer.unref?.();
|
|
1062
1070
|
}
|
|
1063
1071
|
|
package/package.json
CHANGED
package/panel.mjs
CHANGED
|
@@ -79,8 +79,10 @@ export function addStep(steps, line) {
|
|
|
79
79
|
* Long content lives in Telegram's native `<blockquote expandable>`: collapsed it
|
|
80
80
|
* is one line, tapped it shows the whole trail, and it never floods the chat. Two
|
|
81
81
|
* blocks at most — the model's reasoning and, when a turn makes more than three
|
|
82
|
-
* tool calls, the full step list
|
|
83
|
-
*
|
|
82
|
+
* tool calls, the full step list. They appear only in the final edit (`final`):
|
|
83
|
+
* Telegram re-collapses an expanded block on every edit of its message, so a live
|
|
84
|
+
* edit that carried blocks would yank the chat away from whoever is reading one.
|
|
85
|
+
* `plain` is the same content without markup, for the fallback path when
|
|
84
86
|
* the parser refuses a message and for `plainText` installs.
|
|
85
87
|
*/
|
|
86
88
|
export function progressPanel({
|
|
@@ -92,20 +94,29 @@ export function progressPanel({
|
|
|
92
94
|
const mind = thoughts.map((line) => `💭 ${line}`);
|
|
93
95
|
const base = [head, ...mind, cache].filter(Boolean).join('\n').length;
|
|
94
96
|
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
+
// While the turn runs this message is rewritten every few seconds, and
|
|
98
|
+
// Telegram drops an expanded block on every edit — which is what yanks the
|
|
99
|
+
// chat away from someone mid-sentence. So a live edit stays short: the last
|
|
100
|
+
// steps inline, a counter instead of the reasoning, no collapsible content at
|
|
101
|
+
// all. The two blocks arrive once, in the final edit, which nothing touches
|
|
102
|
+
// again, so a block can be opened and read in peace.
|
|
97
103
|
const many = steps.length > 3;
|
|
98
|
-
const inline = many
|
|
104
|
+
const inline = many
|
|
105
|
+
? (final ? [] : steps.slice(-3).map((line) => `• ${line}`))
|
|
106
|
+
: steps.map((line) => `• ${line}`);
|
|
107
|
+
const more = !final && many ? t(lang, 'status.more', { n: steps.length - 3 }) : '';
|
|
108
|
+
const text = String(thinking || '').trim();
|
|
109
|
+
const live = !final && text ? `🧠 ${t(lang, 'status.thinkTitle')} · ${text.length}` : '';
|
|
99
110
|
const stepsRoom = Math.max(0, Math.min(STEPS_MAX, PANEL_MAX - base - 1200));
|
|
100
|
-
const all = many
|
|
111
|
+
const all = many && final
|
|
101
112
|
? tailOf(steps.map((line) => `• ${line}`).join('\n'), stepsRoom)
|
|
102
113
|
: { text: '', cut: false };
|
|
103
114
|
const stepsLabel = `🛠 ${t(lang, 'status.stepsTitle')} · ${steps.length}`
|
|
104
115
|
+ `${all.cut ? ` · ${t(lang, 'status.thinkCut')}` : ''}`;
|
|
105
116
|
|
|
106
|
-
const fixed = base + inline.join('\n').length + all.text.length + 120;
|
|
117
|
+
const fixed = base + inline.join('\n').length + all.text.length + more.length + live.length + 120;
|
|
107
118
|
const room = Math.max(400, Math.min(THINKING_MAX, PANEL_MAX - fixed));
|
|
108
|
-
const body = tailOf(
|
|
119
|
+
const body = final ? tailOf(text, room) : { text: '', cut: false };
|
|
109
120
|
// A cut block starts mid-sentence; say so and point at the one command that
|
|
110
121
|
// still has the whole text, otherwise the reasoning reads as broken.
|
|
111
122
|
const thinkLabel = `🧠 ${t(lang, 'status.thinkTitle')}`
|
|
@@ -114,16 +125,20 @@ export function progressPanel({
|
|
|
114
125
|
const html = [
|
|
115
126
|
head,
|
|
116
127
|
...mind.map((line) => escapeHtml(line)),
|
|
128
|
+
escapeHtml(live),
|
|
117
129
|
body.text ? `<blockquote expandable>${escapeHtml(thinkLabel)}\n${escapeHtml(body.text)}</blockquote>` : '',
|
|
118
130
|
...inline.map((line) => escapeHtml(line)),
|
|
131
|
+
escapeHtml(more),
|
|
119
132
|
all.text ? `<blockquote expandable>${escapeHtml(stepsLabel)}\n${escapeHtml(all.text)}</blockquote>` : '',
|
|
120
133
|
escapeHtml(cache),
|
|
121
134
|
].filter(Boolean).join('\n');
|
|
122
135
|
const plain = [
|
|
123
136
|
head,
|
|
124
137
|
...mind,
|
|
138
|
+
live,
|
|
125
139
|
body.text ? `${thinkLabel}\n${body.text}` : '',
|
|
126
140
|
...inline,
|
|
141
|
+
more,
|
|
127
142
|
all.text ? `${stepsLabel}\n${all.text}` : '',
|
|
128
143
|
cache,
|
|
129
144
|
].filter(Boolean).join('\n');
|