dsh-tg-bridge 1.8.0 → 1.9.0
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 +5 -2
- package/bridge.mjs +6 -3
- package/i18n.mjs +6 -3
- package/package.json +1 -1
- package/panel.mjs +40 -25
package/README.md
CHANGED
|
@@ -16,8 +16,8 @@ blocks.
|
|
|
16
16
|
- **Project per topic**: `/cd my-app`, and all turns run from that directory.
|
|
17
17
|
- **Goal and checklist per topic**: `/goal`, `/task`; both survive restarts and are prepended to every turn.
|
|
18
18
|
- **Live progress**: one edited message per turn — steps, a timer and the cache hit rate, plus
|
|
19
|
-
the model's reasoning in a collapsed block you can tap open
|
|
20
|
-
|
|
19
|
+
the model's reasoning in a collapsed block you can tap open. A long turn adds a second
|
|
20
|
+
collapsed block with every tool call, so the whole run stays in the chat as one message.
|
|
21
21
|
- **No lost messages**: a journal with acknowledgement and replay.
|
|
22
22
|
- **Fail-fast**: when the quota runs out it switches to a free model right away.
|
|
23
23
|
- **`dsh-tg check`**: diagnostics in one command, no changes to the system.
|
|
@@ -269,6 +269,9 @@ rate-limits edits), escaped, and trimmed to its tail when a turn thinks longer t
|
|
|
269
269
|
can hold; the panel never exceeds one message. If the API refuses the markup, the same content
|
|
270
270
|
is retried as plain text.
|
|
271
271
|
|
|
272
|
+
**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 tap away instead of a count.
|
|
274
|
+
|
|
272
275
|
**The agent's own notes.** The agent can add a short decision trail:
|
|
273
276
|
|
|
274
277
|
```bash
|
package/bridge.mjs
CHANGED
|
@@ -1013,16 +1013,19 @@ async function startProgress(chatId, threadId, lang = 'ru') {
|
|
|
1013
1013
|
});
|
|
1014
1014
|
};
|
|
1015
1015
|
|
|
1016
|
-
/** Send or edit the panel; a rejected parse
|
|
1016
|
+
/** Send or edit the panel; `plainText` and a rejected parse fall back to text. */
|
|
1017
1017
|
const post = async (method, payload, view, keyboard = undefined) => {
|
|
1018
|
-
const
|
|
1018
|
+
const markup = config.plainText !== true;
|
|
1019
|
+
const body = markup
|
|
1020
|
+
? { ...payload, text: view.html, parse_mode: 'HTML' }
|
|
1021
|
+
: { ...payload, text: view.plain };
|
|
1019
1022
|
if (keyboard !== undefined) body.reply_markup = keyboard ?? { inline_keyboard: [] };
|
|
1023
|
+
if (!markup) return tg(method, body);
|
|
1020
1024
|
try {
|
|
1021
1025
|
return await tg(method, body);
|
|
1022
1026
|
} catch (error) {
|
|
1023
1027
|
log(`${method} html failed (${String(error.message).slice(0, 100)}); retrying as plain text`);
|
|
1024
1028
|
const plain = { ...payload, text: view.plain };
|
|
1025
|
-
delete plain.parse_mode;
|
|
1026
1029
|
if (keyboard !== undefined) plain.reply_markup = keyboard ?? { inline_keyboard: [] };
|
|
1027
1030
|
return tg(method, plain);
|
|
1028
1031
|
}
|
package/i18n.mjs
CHANGED
|
@@ -31,7 +31,8 @@ const DICT = {
|
|
|
31
31
|
'msg.transcribing': '🎤 Transcribing…',
|
|
32
32
|
'status.steps': 'steps',
|
|
33
33
|
'status.thinking': 'waiting for the model',
|
|
34
|
-
'status.thinkTitle': 'Reasoning',
|
|
34
|
+
'status.thinkTitle': 'Reasoning',
|
|
35
|
+
'status.stepsTitle': 'Steps',
|
|
35
36
|
'status.thinkCut': 'earlier reasoning hidden',
|
|
36
37
|
'err.timeout': 'no activity for {min} min — turn interrupted',
|
|
37
38
|
'err.generic': 'something went wrong',
|
|
@@ -394,7 +395,8 @@ const DICT = {
|
|
|
394
395
|
'msg.transcribing': '🎤 Расшифровываю…',
|
|
395
396
|
'status.steps': 'шагов',
|
|
396
397
|
'status.thinking': 'жду модель',
|
|
397
|
-
'status.thinkTitle': 'Размышления',
|
|
398
|
+
'status.thinkTitle': 'Размышления',
|
|
399
|
+
'status.stepsTitle': 'Шаги',
|
|
398
400
|
'status.thinkCut': 'начало скрыто',
|
|
399
401
|
'err.timeout': 'нет активности {min} мин — ход прерван',
|
|
400
402
|
'err.generic': 'что-то пошло не так',
|
|
@@ -757,7 +759,8 @@ const DICT = {
|
|
|
757
759
|
'msg.transcribing': '🎤 正在转写…',
|
|
758
760
|
'status.steps': '步',
|
|
759
761
|
'status.thinking': '等待模型',
|
|
760
|
-
'status.thinkTitle': '推理',
|
|
762
|
+
'status.thinkTitle': '推理',
|
|
763
|
+
'status.stepsTitle': '步骤',
|
|
761
764
|
'status.thinkCut': '前文已省略',
|
|
762
765
|
'err.timeout': '{min} 分钟无活动 — 已中断',
|
|
763
766
|
'err.generic': '出现错误',
|
package/package.json
CHANGED
package/panel.mjs
CHANGED
|
@@ -18,18 +18,28 @@ function secondsUnit(lang) {
|
|
|
18
18
|
return lang === 'en' ? 's' : lang === 'zh' ? '秒' : 'с';
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
/** How much of the reasoning stream
|
|
22
|
-
const THINKING_MAX =
|
|
21
|
+
/** How much of the reasoning stream a block keeps; the tail is the useful end. */
|
|
22
|
+
const THINKING_MAX = 2000;
|
|
23
23
|
/** Telegram rejects a message over 4096 characters; the rest needs room too. */
|
|
24
24
|
const PANEL_MAX = 3900;
|
|
25
|
+
/** Steps stay short lines, so a long turn can show all of them. */
|
|
26
|
+
const STEPS_MAX = 1600;
|
|
27
|
+
|
|
28
|
+
/** Collapse `text` to its tail, saying so when something was dropped. */
|
|
29
|
+
function tailOf(text, room) {
|
|
30
|
+
if (text.length <= room) return { text, cut: false };
|
|
31
|
+
return { text: text.slice(-room), cut: true };
|
|
32
|
+
}
|
|
25
33
|
|
|
26
34
|
/**
|
|
27
35
|
* One status message per turn, rewritten in place.
|
|
28
36
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
37
|
+
* Long content lives in Telegram's native `<blockquote expandable>`: collapsed it
|
|
38
|
+
* is one line, tapped it shows the whole trail, and it never floods the chat. Two
|
|
39
|
+
* blocks at most — the model's reasoning and, when a turn makes more than three
|
|
40
|
+
* tool calls, the full step list — so the chat still reads as one message per
|
|
41
|
+
* turn. `plain` is the same content without markup, for the fallback path when
|
|
42
|
+
* the parser refuses a message and for `plainText` installs.
|
|
33
43
|
*/
|
|
34
44
|
export function progressPanel({
|
|
35
45
|
lang = 'ru', seconds = 0, final = false, steps = [], thoughts = [], thinking = '', cache = '',
|
|
@@ -38,33 +48,38 @@ export function progressPanel({
|
|
|
38
48
|
? `✅ ${t(lang, 'status.done')} · ${seconds} ${secondsUnit(lang)}`
|
|
39
49
|
: `⏳ ${t(lang, 'status.working')}… ${seconds} ${secondsUnit(lang)}`;
|
|
40
50
|
const mind = thoughts.map((line) => `💭 ${line}`);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const base = [head, ...mind, cache].filter(Boolean).join('\n').length;
|
|
52
|
+
|
|
53
|
+
// Up to three steps fit inline and read better there; a longer turn would turn
|
|
54
|
+
// the panel into a wall of shell commands, so its steps move into a block.
|
|
55
|
+
const many = steps.length > 3;
|
|
56
|
+
const inline = many ? [] : steps.map((line) => `• ${line}`);
|
|
57
|
+
const stepsRoom = Math.max(0, Math.min(STEPS_MAX, PANEL_MAX - base - 1200));
|
|
58
|
+
const all = many
|
|
59
|
+
? tailOf(steps.map((line) => `• ${line}`).join('\n'), stepsRoom)
|
|
60
|
+
: { text: '', cut: false };
|
|
61
|
+
const stepsLabel = `🛠 ${t(lang, 'status.stepsTitle')} · ${steps.length}`
|
|
62
|
+
+ `${all.cut ? ` · ${t(lang, 'status.thinkCut')}` : ''}`;
|
|
63
|
+
|
|
64
|
+
const fixed = base + inline.join('\n').length + all.text.length + 120;
|
|
65
|
+
const room = Math.max(400, Math.min(THINKING_MAX, PANEL_MAX - fixed));
|
|
66
|
+
const body = tailOf(String(thinking || '').trim(), room);
|
|
67
|
+
const thinkLabel = `🧠 ${t(lang, 'status.thinkTitle')}${body.cut ? ` · ${t(lang, 'status.thinkCut')}` : ''}`;
|
|
68
|
+
|
|
54
69
|
const html = [
|
|
55
70
|
head,
|
|
56
71
|
...mind.map((line) => escapeHtml(line)),
|
|
57
|
-
body ? `<blockquote expandable>${escapeHtml(
|
|
58
|
-
...
|
|
59
|
-
escapeHtml(
|
|
72
|
+
body.text ? `<blockquote expandable>${escapeHtml(thinkLabel)}\n${escapeHtml(body.text)}</blockquote>` : '',
|
|
73
|
+
...inline.map((line) => escapeHtml(line)),
|
|
74
|
+
all.text ? `<blockquote expandable>${escapeHtml(stepsLabel)}\n${escapeHtml(all.text)}</blockquote>` : '',
|
|
60
75
|
escapeHtml(cache),
|
|
61
76
|
].filter(Boolean).join('\n');
|
|
62
77
|
const plain = [
|
|
63
78
|
head,
|
|
64
79
|
...mind,
|
|
65
|
-
body ? `${
|
|
66
|
-
...
|
|
67
|
-
|
|
80
|
+
body.text ? `${thinkLabel}\n${body.text}` : '',
|
|
81
|
+
...inline,
|
|
82
|
+
all.text ? `${stepsLabel}\n${all.text}` : '',
|
|
68
83
|
cache,
|
|
69
84
|
].filter(Boolean).join('\n');
|
|
70
85
|
return { html, plain };
|