dsh-tg-bridge 1.19.9 → 1.19.11
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/bridge.mjs +63 -2
- package/i18n/en.mjs +3 -0
- package/i18n/ru.mjs +3 -0
- package/i18n/zh.mjs +3 -0
- package/package.json +1 -1
- package/panel.mjs +9 -3
package/bridge.mjs
CHANGED
|
@@ -736,6 +736,19 @@ function commandOf(text) {
|
|
|
736
736
|
return `/${match[1].toLowerCase().replace(/[.-]+/g, '')}`;
|
|
737
737
|
}
|
|
738
738
|
|
|
739
|
+
/**
|
|
740
|
+
* Commands that may run from the General topic without changing anything there.
|
|
741
|
+
*
|
|
742
|
+
* The lobby rule moves a General message into the newest topic; for these that is
|
|
743
|
+
* the whole point (you want the status of the work you are looking at, and `/stop`
|
|
744
|
+
* must work from anywhere). Everything else is answered in General with the name
|
|
745
|
+
* of the topic it would have changed.
|
|
746
|
+
*/
|
|
747
|
+
const GENERAL_SAFE = new Set([
|
|
748
|
+
'status', 'sessions', 'branches', 'jobs', 'version', 'doctor', 'logs',
|
|
749
|
+
'stop', 'help', 'menu', 'prices', 'thoughts',
|
|
750
|
+
]);
|
|
751
|
+
|
|
739
752
|
/** Canonical immediate command name for a message, or '' when it must queue. */
|
|
740
753
|
function immediateCommandOf(text) {
|
|
741
754
|
const trimmed = String(text ?? '').trim();
|
|
@@ -1133,6 +1146,21 @@ function killTurn(key) {
|
|
|
1133
1146
|
}
|
|
1134
1147
|
|
|
1135
1148
|
|
|
1149
|
+
/**
|
|
1150
|
+
* Average generation speed of a turn, in tokens per second, or 0 when unknown.
|
|
1151
|
+
*
|
|
1152
|
+
* Output tokens over wall time, not over "time spent generating": the bridge
|
|
1153
|
+
* sees one stream and cannot separate thinking from tool calls, and the honest
|
|
1154
|
+
* question the number answers is "is this turn moving", not "how fast is the
|
|
1155
|
+
* provider". A turn younger than a couple of seconds says nothing — one token
|
|
1156
|
+
* in one second is not a measurement.
|
|
1157
|
+
*/
|
|
1158
|
+
function speedOf(outputTokens, ms) {
|
|
1159
|
+
if (!Number.isFinite(outputTokens) || outputTokens <= 0) return 0;
|
|
1160
|
+
if (!Number.isFinite(ms) || ms < 3000) return 0;
|
|
1161
|
+
return Math.round(outputTokens / (ms / 1000));
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1136
1164
|
/**
|
|
1137
1165
|
* One editable status message per turn.
|
|
1138
1166
|
*
|
|
@@ -1152,7 +1180,7 @@ async function startProgress(chatId, threadId, lang = config.lang || 'en', task
|
|
|
1152
1180
|
const steps = [];
|
|
1153
1181
|
const thinkingParts = [];
|
|
1154
1182
|
/** Last reported token usage for this turn, for the cache line. */
|
|
1155
|
-
const usage = { inputTokens: 0, cacheReadTokens: 0 };
|
|
1183
|
+
const usage = { inputTokens: 0, cacheReadTokens: 0, outputTokens: 0 };
|
|
1156
1184
|
let messageId = 0;
|
|
1157
1185
|
let lastEdit = 0;
|
|
1158
1186
|
let dirty = false;
|
|
@@ -1203,6 +1231,11 @@ async function startProgress(chatId, threadId, lang = config.lang || 'en', task
|
|
|
1203
1231
|
// name comes from Telegram, cached: one API call per topic per process.
|
|
1204
1232
|
topic: threadId ? t(lang, 'bridge.progress.topic', { n: threadId, name: topicName(chatId, threadId) || t(lang, 'bridge.progress.topicNoName') }) : '',
|
|
1205
1233
|
seconds: Math.round((Date.now() - started) / 1000),
|
|
1234
|
+
// How fast this turn is actually generating, in tokens per second. The
|
|
1235
|
+
// number is the turn's average — output tokens over wall time — because
|
|
1236
|
+
// that is what "долго" means to the reader: a slow provider and a turn
|
|
1237
|
+
// that spends its minutes in tools look identical without it.
|
|
1238
|
+
speed: speedOf(usage.outputTokens, Date.now() - started),
|
|
1206
1239
|
final,
|
|
1207
1240
|
steps,
|
|
1208
1241
|
thoughts,
|
|
@@ -1317,10 +1350,14 @@ async function startProgress(chatId, threadId, lang = config.lang || 'en', task
|
|
|
1317
1350
|
return;
|
|
1318
1351
|
}
|
|
1319
1352
|
// Usage rides on the status events; keep the latest numbers so the final
|
|
1320
|
-
// line can show the cache hit rate of this very turn
|
|
1353
|
+
// line can show the cache hit rate of this very turn, and so the head can
|
|
1354
|
+
// show how fast it is going — "долго" is usually either a slow provider or
|
|
1355
|
+
// a turn that spends its time in tools, and the panel could not tell them
|
|
1356
|
+
// apart.
|
|
1321
1357
|
if (event.type === 'status' && event.usage) {
|
|
1322
1358
|
if (Number.isFinite(event.usage.inputTokens)) usage.inputTokens = event.usage.inputTokens;
|
|
1323
1359
|
if (Number.isFinite(event.usage.cacheReadTokens)) usage.cacheReadTokens = event.usage.cacheReadTokens;
|
|
1360
|
+
if (Number.isFinite(event.usage.outputTokens)) usage.outputTokens = event.usage.outputTokens;
|
|
1324
1361
|
schedule();
|
|
1325
1362
|
return;
|
|
1326
1363
|
}
|
|
@@ -1530,6 +1567,9 @@ async function handleMessage(msg, album = null) {
|
|
|
1530
1567
|
}
|
|
1531
1568
|
|
|
1532
1569
|
let threadId = threadOf(msg);
|
|
1570
|
+
// Whether the person typed in the General topic (the "All" stream), before the
|
|
1571
|
+
// lobby rule below moves the message into a topic.
|
|
1572
|
+
const typedInGeneral = threadId === 0;
|
|
1533
1573
|
// 3. The General-chat twin of an already-seeded topic: keep the log line,
|
|
1534
1574
|
// skip the turn — the topic message already owns this work.
|
|
1535
1575
|
const twin = threadId === 0 ? topicSeededRecently(msg.text ?? msg.caption ?? '') : 0;
|
|
@@ -1550,6 +1590,8 @@ async function handleMessage(msg, album = null) {
|
|
|
1550
1590
|
threadId = recovered;
|
|
1551
1591
|
}
|
|
1552
1592
|
}
|
|
1593
|
+
// The topic a General message was moved into, or 0 when it stayed where it was.
|
|
1594
|
+
const recoveredTopic = typedInGeneral && threadId > 0 ? threadId : 0;
|
|
1553
1595
|
touchTopic(threadId);
|
|
1554
1596
|
|
|
1555
1597
|
const key = sessionKey(chatId, threadId);
|
|
@@ -1645,6 +1687,19 @@ async function handleMessage(msg, album = null) {
|
|
|
1645
1687
|
}
|
|
1646
1688
|
if (effectiveArg === 'restartconfirm' || effectiveArg === 'restart.confirm') effectiveArg = 'restart confirm';
|
|
1647
1689
|
|
|
1690
|
+
// General is the lobby: a prompt written there runs in the most recently active
|
|
1691
|
+
// topic so one project stays in one place. A command that CHANGES things must
|
|
1692
|
+
// not silently change a topic the person is not looking at — `/new` there wiped
|
|
1693
|
+
// the session of another topic and `/rewind` rolled one back, and the answer
|
|
1694
|
+
// appeared in that topic rather than where it was typed. Reading commands and
|
|
1695
|
+
// `/stop` still follow the work, because that is what the lobby is for.
|
|
1696
|
+
if (recoveredTopic > 0 && effective && !GENERAL_SAFE.has(effective.slice(1))) {
|
|
1697
|
+
const named = topicName(chatId, recoveredTopic) || `#${recoveredTopic}`;
|
|
1698
|
+
log(`refused ${effective} in General; it belongs to topic ${recoveredTopic}`);
|
|
1699
|
+
await send(chatId, t(lang, 'msg.generalGuard', { cmd: effective, topic: named }), 0);
|
|
1700
|
+
return;
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1648
1703
|
// An unknown slash command must never become an AI turn: it burns money and
|
|
1649
1704
|
// answers something the person did not ask. Answer with the menu instead.
|
|
1650
1705
|
if (command && !effective) {
|
|
@@ -2037,6 +2092,12 @@ function steerRunningTurn(msg, text, sessionId, thread) {
|
|
|
2037
2092
|
say: SAY,
|
|
2038
2093
|
});
|
|
2039
2094
|
log(`steer ${job.id} -> ${sessionId} (${text.length} chars)`);
|
|
2095
|
+
// Confirm the moment the job is written, not 90 seconds later. The plugin
|
|
2096
|
+
// hands it to the running agent at its next step, and a step can be a
|
|
2097
|
+
// six-minute test run: without this line the addition looked lost, which is
|
|
2098
|
+
// exactly what "steer стала хуже" describes. The wait notice below then only
|
|
2099
|
+
// speaks when the job really has not been picked up.
|
|
2100
|
+
send(msg.chat.id, t(lang, 'steer.queued'), thread).catch(() => {});
|
|
2040
2101
|
watchSteer(job, msg, text, thread, lang);
|
|
2041
2102
|
return job;
|
|
2042
2103
|
}
|
package/i18n/en.mjs
CHANGED
|
@@ -197,6 +197,7 @@ export default {
|
|
|
197
197
|
'btn.doctor': 'Doctor',
|
|
198
198
|
'status.cache': 'cache',
|
|
199
199
|
'status.more': '…and {n} more',
|
|
200
|
+
'status.speed': 'tok/s',
|
|
200
201
|
'status.cacheLine': '🧠 cache: {pct}% ({k}k from cache)',
|
|
201
202
|
'msg.topicLog': '📌 New topic: {preview}\n→ work happens in the topic, this is the log.',
|
|
202
203
|
'msg.transcribing': '🎤 Transcribing…',
|
|
@@ -209,11 +210,13 @@ export default {
|
|
|
209
210
|
'err.generic': 'something went wrong',
|
|
210
211
|
'msg.busy.since': '⏳ The previous turn has been running for {min} min — your message is queued.\nIf it stalls, /stop interrupts it and I take yours right away.',
|
|
211
212
|
'msg.busy.now': '⏳ The previous turn is still running — your message is queued.\nIf it stalls, /stop interrupts it and I take yours right away.',
|
|
213
|
+
'steer.queued': '↪ Addition received — I will fold it in at the next step of this turn.',
|
|
212
214
|
'steer.ackFallback': '↪ Got the addition — folding it into this turn.',
|
|
213
215
|
'msg.started': 'Telegram bridge for DSH is running (headless). Send a task; /help for commands.',
|
|
214
216
|
'msg.restarted': 'Bridge restarted — back online (pid {pid}).\nThe topic and session are the same; keep going.',
|
|
215
217
|
'cmd.restart.prompt': 'To restart the bridge: /restart confirm. For the DSH app: /app restart confirm.',
|
|
216
218
|
'cmd.restart.started': 'Restarting the bridge…',
|
|
219
|
+
'msg.generalGuard': "This is the General topic, where topics are started. {cmd} changes “{topic}”, so open that topic and send it there. Reading works here: /status, /sessions, /stop.",
|
|
217
220
|
'msg.unknownCommand': 'Unknown command: {cmd}. Open /help — it lists everything this bot can do.',
|
|
218
221
|
'msg.langSet': 'Language set to English.',
|
|
219
222
|
'msg.reasoningOn': 'Working notes on: 💭 lines will appear in the progress message.\nOff: /reasoning off',
|
package/i18n/ru.mjs
CHANGED
|
@@ -197,6 +197,7 @@ export default {
|
|
|
197
197
|
'btn.doctor': 'Диагноз',
|
|
198
198
|
'status.cache': 'кэш',
|
|
199
199
|
'status.more': '…и ещё {n}',
|
|
200
|
+
'status.speed': 'т/с',
|
|
200
201
|
'status.cacheLine': '🧠 кэш: {pct}% ({k}k из кэша)',
|
|
201
202
|
'msg.topicLog': '📌 Новая тема: {preview}\n→ работа идёт в теме, здесь — лог.',
|
|
202
203
|
'msg.transcribing': '🎤 Расшифровываю…',
|
|
@@ -209,11 +210,13 @@ export default {
|
|
|
209
210
|
'err.generic': 'что-то пошло не так',
|
|
210
211
|
'msg.busy.since': '⏳ Предыдущий ход идёт уже {min} мин — твоё сообщение в очереди.\nЕсли это затянулось, /stop прервёт ход, и я сразу возьмусь за твоим.',
|
|
211
212
|
'msg.busy.now': '⏳ Предыдущий ход ещё идёт — твоё сообщение в очереди.\nЕсли это затянулось, /stop прервёт ход, и я сразу возьмусь за твоим.',
|
|
213
|
+
'steer.queued': '↪ Дополнение принято — передам его на следующем шаге этого хода.',
|
|
212
214
|
'steer.ackFallback': '↪ Принял дополнение — учту его в этом же ходе.',
|
|
213
215
|
'msg.started': 'Telegram-мост DSH запущен (headless). Пиши задачу; /help — команды.',
|
|
214
216
|
'msg.restarted': 'Мост перезапущен — на связи (pid {pid}).\nТема и сессия прежние, можно продолжать.',
|
|
215
217
|
'cmd.restart.prompt': 'Перезапуск моста: /restart confirm. Приложение DSH: /app restart confirm.',
|
|
216
218
|
'cmd.restart.started': 'Перезапускаю мост…',
|
|
219
|
+
'msg.generalGuard': "Это общая тема «Все» — здесь темы начинаются. {cmd} меняет «{topic}», поэтому откройте ту тему и отправьте команду там. Читать можно и здесь: /status, /sessions, /stop.",
|
|
217
220
|
'msg.unknownCommand': 'Неизвестная команда: {cmd}. Открой /help — там всё, что умеет бот.',
|
|
218
221
|
'msg.langSet': 'Язык переключён на русский.',
|
|
219
222
|
'msg.reasoningOn': 'Заметки по ходу включены: 💭 будут появляться в сообщении прогресса.\nВыключить: /reasoning off',
|
package/i18n/zh.mjs
CHANGED
|
@@ -197,6 +197,7 @@ export default {
|
|
|
197
197
|
'btn.doctor': '诊断',
|
|
198
198
|
'status.cache': '缓存',
|
|
199
199
|
'status.more': '…还有 {n} 条',
|
|
200
|
+
'status.speed': 'tok/s',
|
|
200
201
|
'status.cacheLine': '🧠 缓存:{pct}%({k}k 来自缓存)',
|
|
201
202
|
'msg.topicLog': '📌 新主题:{preview}\n→ 工作在主题里进行,这里是日志。',
|
|
202
203
|
'msg.transcribing': '🎤 正在转写…',
|
|
@@ -209,11 +210,13 @@ export default {
|
|
|
209
210
|
'err.generic': '出现错误',
|
|
210
211
|
'msg.busy.since': '⏳ 上一轮已运行 {min} 分钟 —— 你的消息在队列中。\n如果太久,/stop 会中断它,我马上处理你的消息。',
|
|
211
212
|
'msg.busy.now': '⏳ 上一轮还在运行 —— 你的消息在队列中。\n如果太久,/stop 会中断它,我马上处理你的消息。',
|
|
213
|
+
'steer.queued': '↪ 已收到补充 — 会在这一轮的下一步并入。',
|
|
212
214
|
'steer.ackFallback': '↪ 收到补充,会在本轮里一并处理。',
|
|
213
215
|
'msg.started': 'DSH 的 Telegram 桥已启动(headless)。直接发送任务;/help 查看命令。',
|
|
214
216
|
'msg.restarted': '桥已重启,连接正常(pid {pid})。\n主题和会话不变,可以继续。',
|
|
215
217
|
'cmd.restart.prompt': '重启桥:/restart confirm。重启 DSH 应用:/app restart confirm。',
|
|
216
218
|
'cmd.restart.started': '正在重启桥…',
|
|
219
|
+
'msg.generalGuard': "这里是「全部」主题,用来开新话题。{cmd} 会改动「{topic}」,请打开那个话题再发送。这里可以直接读:/status、/sessions、/stop。",
|
|
217
220
|
'msg.unknownCommand': '未知命令:{cmd}。打开 /help 查看机器人支持的全部命令。',
|
|
218
221
|
'msg.langSet': '界面语言已切换为中文。',
|
|
219
222
|
'msg.reasoningOn': '工作记录已开启:💭 会显示在进度消息里。\n关闭:/reasoning off',
|
package/package.json
CHANGED
package/panel.mjs
CHANGED
|
@@ -101,15 +101,21 @@ export function progressPanel({
|
|
|
101
101
|
// group can run two topics at once and the cards look identical; the head is
|
|
102
102
|
// the only part that survives the card being quoted or forwarded.
|
|
103
103
|
topic = '',
|
|
104
|
+
// Average generation speed of this turn in tokens per second, 0 when unknown.
|
|
105
|
+
// It rides in the head next to the clock: the clock alone cannot tell a slow
|
|
106
|
+
// provider from a turn that spends its minutes in tools.
|
|
107
|
+
speed = 0,
|
|
104
108
|
} = {}) {
|
|
105
109
|
const snippet = String(task).replace(/\s+/g, ' ').trim().slice(0, 48);
|
|
106
110
|
const mark = String(chip).trim() ? ` · ${String(chip).trim()}` : '';
|
|
107
111
|
const where = String(topic || '').trim() ? `\n${String(topic).trim()}` : '';
|
|
112
|
+
// The speed sits right after the clock so the two read as one measurement.
|
|
113
|
+
const rate = Number(speed) > 0 ? ` · ${Math.round(Number(speed))} ${t(lang, 'status.speed')}` : '';
|
|
108
114
|
const head = final
|
|
109
|
-
? `✅ ${t(lang, 'status.done')} · ${seconds} ${secondsUnit(lang)}${mark}${where}`
|
|
115
|
+
? `✅ ${t(lang, 'status.done')} · ${seconds} ${secondsUnit(lang)}${rate}${mark}${where}`
|
|
110
116
|
: snippet
|
|
111
|
-
? `⏳ ${t(lang, 'status.accepted')}: «${snippet}${String(task).trim().length > 48 ? '…' : ''}» · ${seconds} ${secondsUnit(lang)}${mark}${where}`
|
|
112
|
-
: `⏳ ${t(lang, 'status.working')}… ${seconds} ${secondsUnit(lang)}${mark}${where}`;
|
|
117
|
+
? `⏳ ${t(lang, 'status.accepted')}: «${snippet}${String(task).trim().length > 48 ? '…' : ''}» · ${seconds} ${secondsUnit(lang)}${rate}${mark}${where}`
|
|
118
|
+
: `⏳ ${t(lang, 'status.working')}… ${seconds} ${secondsUnit(lang)}${rate}${mark}${where}`;
|
|
113
119
|
const mind = thoughts.map((line) => `💭 ${line}`);
|
|
114
120
|
const base = [head, ...mind, cache].filter(Boolean).join('\n').length;
|
|
115
121
|
|