dsh-tg-bridge 1.7.2 → 1.7.4
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 +13 -1
- package/control.mjs +49 -22
- package/i18n.mjs +24 -12
- package/package.json +1 -1
package/bridge.mjs
CHANGED
|
@@ -2301,10 +2301,22 @@ async function main() {
|
|
|
2301
2301
|
|
|
2302
2302
|
// Replay anything the previous process owed an answer. Runs before polling so
|
|
2303
2303
|
// a crash mid-turn costs one duplicate-free retry, not a lost message.
|
|
2304
|
+
//
|
|
2305
|
+
// One bad entry must not become a restart loop: `accept` throwing here used to
|
|
2306
|
+
// leave the update pending forever, so the bridge replayed it, died, and was
|
|
2307
|
+
// restarted by the supervisor — every ninety seconds, with a stack trace and
|
|
2308
|
+
// nothing else. Drop the entry after reporting it.
|
|
2304
2309
|
const owed = pendingUpdates();
|
|
2305
2310
|
if (owed.length > 0) {
|
|
2306
2311
|
log(`replaying ${owed.length} pending update(s) from the journal`);
|
|
2307
|
-
for (const { update } of owed)
|
|
2312
|
+
for (const { update } of owed) {
|
|
2313
|
+
try {
|
|
2314
|
+
accept(update, true);
|
|
2315
|
+
} catch (error) {
|
|
2316
|
+
log(`replay of update ${update?.update_id} failed, dropping it: ${error.message}`);
|
|
2317
|
+
ack(update?.update_id);
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2308
2320
|
}
|
|
2309
2321
|
|
|
2310
2322
|
let pollFailures = 0;
|
package/control.mjs
CHANGED
|
@@ -438,6 +438,32 @@ export function reasoningOf(state, config, key) {
|
|
|
438
438
|
return config?.reasoning !== false;
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
+
/**
|
|
442
|
+
* The chat view of `bridge.log`. Delivery chatter ("sent chat=…") answers
|
|
443
|
+
* nothing when the question is "what did the agent do", so the default view
|
|
444
|
+
* hides it — it stays in the file for delivery debugging. `errors` keeps the
|
|
445
|
+
* bridge's own faults and drops tool results, which are part of the work.
|
|
446
|
+
*/
|
|
447
|
+
export function filterLogLines(lines, filter, count) {
|
|
448
|
+
const isChatter = (line) =>
|
|
449
|
+
/\bsent chat=/.test(line)
|
|
450
|
+
|| /\bin \d+ /.test(line)
|
|
451
|
+
|| /bridge started|bot @|replaying \d+ pending|topic \d+ (?:seeded|logged)/.test(line);
|
|
452
|
+
const isToolLine = (line) => line.includes('tool[') || /\]\s+(?:pwsh|bash|shell)\b/.test(line);
|
|
453
|
+
|
|
454
|
+
let pool;
|
|
455
|
+
if (filter === 'errors') {
|
|
456
|
+
pool = lines.filter((line) => !isToolLine(line)
|
|
457
|
+
&& /turn failed|FATAL|unhandled|poll error|Conflict|quota|AUTH|exiting code=[1-9]|cannot |failed to/i.test(line));
|
|
458
|
+
} else if (filter) {
|
|
459
|
+
const needle = filter.toLowerCase();
|
|
460
|
+
pool = lines.filter((line) => line.toLowerCase().includes(needle));
|
|
461
|
+
} else {
|
|
462
|
+
pool = lines.filter((line) => !isChatter(line));
|
|
463
|
+
}
|
|
464
|
+
return { pool, tail: pool.slice(-count) };
|
|
465
|
+
}
|
|
466
|
+
|
|
441
467
|
export async function handleControl(ctx) {
|
|
442
468
|
const { command, arg, send, reply, log, profile, state, key, config, lang } = ctx;
|
|
443
469
|
const say = (text) => reply(text);
|
|
@@ -470,7 +496,7 @@ export async function handleControl(ctx) {
|
|
|
470
496
|
const stats = sessionId ? sessionStats(sessionFile(join(DSH_HOME, 'sessions'), sessionId)) : null;
|
|
471
497
|
const title = sessionId ? state.titles?.[key] : '';
|
|
472
498
|
const lines = [t(lang, 'ctrl.status.head')];
|
|
473
|
-
lines.push(t(lang, 'ctrl.status.session', { id: sessionId
|
|
499
|
+
lines.push(t(lang, 'ctrl.status.session', { id: sessionId || t(lang, 'ctrl.session.none') }));
|
|
474
500
|
if (title) lines.push(t(lang, 'ctrl.status.title', { title }));
|
|
475
501
|
lines.push(t(lang, 'ctrl.status.profile', { name: activeProfile, route: `${head.provider}/${head.model}` }));
|
|
476
502
|
lines.push(t(lang, 'ctrl.status.thread', { name: ctx.threadId || t(lang, 'ctrl.status.threadDefault') }));
|
|
@@ -490,7 +516,10 @@ export async function handleControl(ctx) {
|
|
|
490
516
|
lines.push(t(lang, 'ctrl.status.lifetime', { n: stats.lifetimeTokens.toLocaleString('en-US') }));
|
|
491
517
|
}
|
|
492
518
|
if (stats?.turns) lines.push(t(lang, 'ctrl.status.steps', { n: stats.turns }));
|
|
493
|
-
lines.push(t(lang, 'ctrl.status.turns', {
|
|
519
|
+
lines.push(t(lang, 'ctrl.status.turns', {
|
|
520
|
+
n: active,
|
|
521
|
+
state: active > 0 ? t(lang, 'ctrl.status.running') : t(lang, 'ctrl.status.idle'),
|
|
522
|
+
}));
|
|
494
523
|
lines.push(t(lang, 'ctrl.status.notes', {
|
|
495
524
|
state: reasoningOf(state, config, key) ? t(lang, 'ctrl.status.on') : t(lang, 'ctrl.status.off'),
|
|
496
525
|
}));
|
|
@@ -1123,8 +1152,24 @@ export async function handleControl(ctx) {
|
|
|
1123
1152
|
|
|
1124
1153
|
case '/logs': {
|
|
1125
1154
|
// `/logs` — meaningful events, `/logs 100` — more, `/logs <text>` —
|
|
1126
|
-
// filter, `/logs errors` — failures only
|
|
1155
|
+
// filter, `/logs errors` — failures only, `/logs file` — the whole file
|
|
1156
|
+
// as a document, when the answer needs the part chat cannot hold.
|
|
1127
1157
|
const file = join(DSH_HOME, 'tg-bridge', 'bridge.log');
|
|
1158
|
+
const wanted = (arg || '').trim();
|
|
1159
|
+
if (/^(file|full|all|файл|файлом|全文|文件)$/i.test(wanted)) {
|
|
1160
|
+
if (!ctx.sendFile) {
|
|
1161
|
+
say(t(lang, 'ctrl.logs.noFileChannel'));
|
|
1162
|
+
return true;
|
|
1163
|
+
}
|
|
1164
|
+
try {
|
|
1165
|
+
await ctx.sendFile(file, t(lang, 'ctrl.logs.fileCaption', {
|
|
1166
|
+
mb: (statSync(file).size / 1024 ** 2).toFixed(1),
|
|
1167
|
+
}));
|
|
1168
|
+
} catch (error) {
|
|
1169
|
+
say(t(lang, 'ctrl.logs.unreadable', { err: error.message }));
|
|
1170
|
+
}
|
|
1171
|
+
return true;
|
|
1172
|
+
}
|
|
1128
1173
|
let lines = [];
|
|
1129
1174
|
try {
|
|
1130
1175
|
lines = readFileSync(file, 'utf8').split(/\r?\n/).filter(Boolean);
|
|
@@ -1135,30 +1180,12 @@ export async function handleControl(ctx) {
|
|
|
1135
1180
|
const numeric = Number(arg);
|
|
1136
1181
|
const count = Number.isInteger(numeric) && numeric > 0 ? Math.min(numeric, 200) : 30;
|
|
1137
1182
|
const filter = Number.isInteger(numeric) ? '' : (arg || '').trim();
|
|
1138
|
-
|
|
1139
|
-
// Delivery chatter ("in 123", "sent chat=...") answers nothing when the
|
|
1140
|
-
// question is "what did the agent do". It stays in the file for delivery
|
|
1141
|
-
// debugging but is hidden from the chat view.
|
|
1142
|
-
const isChatter = (line) =>
|
|
1143
|
-
/\bsent chat=/.test(line)
|
|
1144
|
-
|| /\bin \d+ /.test(line)
|
|
1145
|
-
|| /bridge started|bot @|replaying \d+ pending|topic \d+ (?:seeded|logged)/.test(line);
|
|
1146
|
-
|
|
1147
|
-
let pool;
|
|
1148
|
-
if (filter === 'errors') {
|
|
1149
|
-
pool = lines.filter((line) => /turn failed|ОШИБКА|error|poll error|409|Conflict|quota|AUTH/i.test(line));
|
|
1150
|
-
} else if (filter) {
|
|
1151
|
-
const needle = filter.toLowerCase();
|
|
1152
|
-
pool = lines.filter((line) => line.toLowerCase().includes(needle));
|
|
1153
|
-
} else {
|
|
1154
|
-
pool = lines.filter((line) => !isChatter(line));
|
|
1155
|
-
}
|
|
1183
|
+
const { pool, tail } = filterLogLines(lines, filter, count);
|
|
1156
1184
|
|
|
1157
1185
|
if (pool.length === 0) {
|
|
1158
1186
|
say(filter ? t(lang, 'ctrl.logs.noMatch', { filter }) : t(lang, 'ctrl.logs.empty'));
|
|
1159
1187
|
return true;
|
|
1160
1188
|
}
|
|
1161
|
-
const tail = pool.slice(-count);
|
|
1162
1189
|
const header = filter === 'errors'
|
|
1163
1190
|
? t(lang, 'ctrl.logs.errors', { shown: tail.length, total: pool.length })
|
|
1164
1191
|
: t(lang, 'ctrl.logs.title', { shown: tail.length, total: pool.length });
|
package/i18n.mjs
CHANGED
|
@@ -81,7 +81,9 @@ const DICT = {
|
|
|
81
81
|
'ctrl.status.contextNoWindow': 'Context: {now} tokens (window unknown: set contextWindow in config.json)',
|
|
82
82
|
'ctrl.status.lifetime': 'Session tokens billed: {n}',
|
|
83
83
|
'ctrl.status.steps': 'Turns in the session: {n}',
|
|
84
|
-
'ctrl.status.turns': '
|
|
84
|
+
'ctrl.status.turns': 'Agent running: {state} ({n} turn(s))',
|
|
85
|
+
'ctrl.status.running': 'yes',
|
|
86
|
+
'ctrl.status.idle': 'no',
|
|
85
87
|
'ctrl.status.notes': 'Working notes (💭 in progress): {state}',
|
|
86
88
|
'ctrl.status.on': 'on',
|
|
87
89
|
'ctrl.status.off': 'off',
|
|
@@ -95,7 +97,7 @@ const DICT = {
|
|
|
95
97
|
'ctrl.model.switched': 'Model {name} → {model}{desktop}. Applies from the next turn.',
|
|
96
98
|
'ctrl.model.withDesktop': ', desktop → {model}',
|
|
97
99
|
'ctrl.sessions.empty': 'No sessions found.',
|
|
98
|
-
'ctrl.sessions.title': 'Recent sessions:',
|
|
100
|
+
'ctrl.sessions.title': '🗂 Recent sessions:',
|
|
99
101
|
'ctrl.sessions.untitled': '(untitled)',
|
|
100
102
|
'ctrl.resume.usage': 'Usage: /resume <id> (/sessions — list)',
|
|
101
103
|
'ctrl.resume.done': 'This topic will continue session {id}.',
|
|
@@ -127,7 +129,7 @@ const DICT = {
|
|
|
127
129
|
'ctrl.soul.title': 'Persona ({path}):\n\n{text}',
|
|
128
130
|
'ctrl.soul.empty': 'Persona is empty. Set it: /soul <text>\nFile: {path}',
|
|
129
131
|
'ctrl.soul.saved': 'Persona updated in ~/.dsh/AGENTS.md. Applies to new sessions.',
|
|
130
|
-
'ctrl.version.title': 'Versions',
|
|
132
|
+
'ctrl.version.title': '📦 Versions',
|
|
131
133
|
'ctrl.version.installed': 'Installed here: {v}',
|
|
132
134
|
'ctrl.version.latest': 'Latest on npm: {v}',
|
|
133
135
|
'ctrl.version.unknown': 'unknown',
|
|
@@ -169,7 +171,7 @@ const DICT = {
|
|
|
169
171
|
'ctrl.seed.failed': 'Could not seed the topic — check the bridge log.',
|
|
170
172
|
'ctrl.lang.state': 'Language: {lang}\nAvailable: {list}\nSwitch: /lang en',
|
|
171
173
|
'ctrl.lang.auto': 'auto',
|
|
172
|
-
'ctrl.doctor.title': 'Diagnostics',
|
|
174
|
+
'ctrl.doctor.title': '🩺 Diagnostics',
|
|
173
175
|
'ctrl.doctor.bridgePid': 'Bridge pid',
|
|
174
176
|
'ctrl.doctor.noPidFile': 'no pid file',
|
|
175
177
|
'ctrl.doctor.bridgeAlive': 'Bridge alive',
|
|
@@ -195,6 +197,8 @@ const DICT = {
|
|
|
195
197
|
'ctrl.logs.empty': 'The log is empty.',
|
|
196
198
|
'ctrl.logs.errors': 'Errors ({shown} of {total})',
|
|
197
199
|
'ctrl.logs.title': 'Log ({shown} of {total})',
|
|
200
|
+
'ctrl.logs.fileCaption': 'bridge.log, {mb} MB — the whole file',
|
|
201
|
+
'ctrl.logs.noFileChannel': 'This bridge build cannot send files; use /logs 200.',
|
|
198
202
|
'ctrl.thoughts.title': '🧠 Reasoning of the last turn ({chars} chars, kept for a few minutes):',
|
|
199
203
|
'ctrl.thoughts.none': 'The last turn stored no reasoning plan.',
|
|
200
204
|
'ctrl.thoughts.lastAnswer': 'What the last turn answered:',
|
|
@@ -349,7 +353,9 @@ const DICT = {
|
|
|
349
353
|
'ctrl.status.contextNoWindow': 'Контекст: {now} токенов (окно неизвестно: укажи contextWindow в config.json)',
|
|
350
354
|
'ctrl.status.lifetime': 'Токенов за сессию: {n}',
|
|
351
355
|
'ctrl.status.steps': 'Ходов в сессии: {n}',
|
|
352
|
-
'ctrl.status.turns': '
|
|
356
|
+
'ctrl.status.turns': 'Агент работает: {state} ({n} ход(ов))',
|
|
357
|
+
'ctrl.status.running': 'да',
|
|
358
|
+
'ctrl.status.idle': 'нет',
|
|
353
359
|
'ctrl.status.notes': 'Заметки по ходу (💭 в прогрессе): {state}',
|
|
354
360
|
'ctrl.status.on': 'включены',
|
|
355
361
|
'ctrl.status.off': 'выключены',
|
|
@@ -363,7 +369,7 @@ const DICT = {
|
|
|
363
369
|
'ctrl.model.switched': 'Модель {name} → {model}{desktop}. Действует со следующего хода.',
|
|
364
370
|
'ctrl.model.withDesktop': ', desktop → {model}',
|
|
365
371
|
'ctrl.sessions.empty': 'Сессий не нашёл.',
|
|
366
|
-
'ctrl.sessions.title': 'Последние сессии:',
|
|
372
|
+
'ctrl.sessions.title': '🗂 Последние сессии:',
|
|
367
373
|
'ctrl.sessions.untitled': '(без названия)',
|
|
368
374
|
'ctrl.resume.usage': 'Использование: /resume <id> (/sessions — список)',
|
|
369
375
|
'ctrl.resume.done': 'Эта ветка продолжит сессию {id}.',
|
|
@@ -395,7 +401,7 @@ const DICT = {
|
|
|
395
401
|
'ctrl.soul.title': 'Персона ({path}):\n\n{text}',
|
|
396
402
|
'ctrl.soul.empty': 'Персона пуста. Задать: /soul <text>\nФайл: {path}',
|
|
397
403
|
'ctrl.soul.saved': 'Персона обновлена в ~/.dsh/AGENTS.md. Применяется в новых сессиях.',
|
|
398
|
-
'ctrl.version.title': 'Версии',
|
|
404
|
+
'ctrl.version.title': '📦 Версии',
|
|
399
405
|
'ctrl.version.installed': 'Установлено здесь: {v}',
|
|
400
406
|
'ctrl.version.latest': 'Последняя на npm: {v}',
|
|
401
407
|
'ctrl.version.unknown': 'неизвестно',
|
|
@@ -437,7 +443,7 @@ const DICT = {
|
|
|
437
443
|
'ctrl.seed.failed': 'Не смог засеять тему — смотри лог моста.',
|
|
438
444
|
'ctrl.lang.state': 'Язык: {lang}\nДоступно: {list}\nПереключить: /lang en',
|
|
439
445
|
'ctrl.lang.auto': 'auto',
|
|
440
|
-
'ctrl.doctor.title': 'Диагностика',
|
|
446
|
+
'ctrl.doctor.title': '🩺 Диагностика',
|
|
441
447
|
'ctrl.doctor.bridgePid': 'Мост pid',
|
|
442
448
|
'ctrl.doctor.noPidFile': 'нет файла',
|
|
443
449
|
'ctrl.doctor.bridgeAlive': 'Мост жив',
|
|
@@ -463,6 +469,8 @@ const DICT = {
|
|
|
463
469
|
'ctrl.logs.empty': 'Лог пуст.',
|
|
464
470
|
'ctrl.logs.errors': 'Ошибки ({shown} из {total})',
|
|
465
471
|
'ctrl.logs.title': 'Лог ({shown} из {total})',
|
|
472
|
+
'ctrl.logs.fileCaption': 'bridge.log, {mb} МБ — файл целиком',
|
|
473
|
+
'ctrl.logs.noFileChannel': 'Эта сборка моста не умеет отправлять файлы; используй /logs 200.',
|
|
466
474
|
'ctrl.thoughts.title': '🧠 Рассуждения последнего хода ({chars} символов, повисят несколько минут):',
|
|
467
475
|
'ctrl.thoughts.none': 'В последнем ходе не сохранилось плана рассуждений.',
|
|
468
476
|
'ctrl.thoughts.lastAnswer': 'Последний ход ответил так:',
|
|
@@ -617,7 +625,9 @@ const DICT = {
|
|
|
617
625
|
'ctrl.status.contextNoWindow': '上下文:{now} 个 token(窗口未知:在 config.json 里设置 contextWindow)',
|
|
618
626
|
'ctrl.status.lifetime': '本会话累计 token:{n}',
|
|
619
627
|
'ctrl.status.steps': '会话中的轮次:{n}',
|
|
620
|
-
'ctrl.status.turns': '
|
|
628
|
+
'ctrl.status.turns': '代理运行中:{state}({n} 个任务)',
|
|
629
|
+
'ctrl.status.running': '是',
|
|
630
|
+
'ctrl.status.idle': '否',
|
|
621
631
|
'ctrl.status.notes': '工作记录(进度中的 💭):{state}',
|
|
622
632
|
'ctrl.status.on': '开',
|
|
623
633
|
'ctrl.status.off': '关',
|
|
@@ -631,7 +641,7 @@ const DICT = {
|
|
|
631
641
|
'ctrl.model.switched': '模型 {name} → {model}{desktop}。下一轮生效。',
|
|
632
642
|
'ctrl.model.withDesktop': ',desktop → {model}',
|
|
633
643
|
'ctrl.sessions.empty': '没有找到会话。',
|
|
634
|
-
'ctrl.sessions.title': '最近的会话:',
|
|
644
|
+
'ctrl.sessions.title': '🗂 最近的会话:',
|
|
635
645
|
'ctrl.sessions.untitled': '(无标题)',
|
|
636
646
|
'ctrl.resume.usage': '用法:/resume <id> (/sessions 查看列表)',
|
|
637
647
|
'ctrl.resume.done': '本话题将接着使用会话 {id}。',
|
|
@@ -663,7 +673,7 @@ const DICT = {
|
|
|
663
673
|
'ctrl.soul.title': '人格({path}):\n\n{text}',
|
|
664
674
|
'ctrl.soul.empty': '人格为空。设置:/soul <文本>\n文件:{path}',
|
|
665
675
|
'ctrl.soul.saved': '人格已更新到 ~/.dsh/AGENTS.md。对新会话生效。',
|
|
666
|
-
'ctrl.version.title': '版本',
|
|
676
|
+
'ctrl.version.title': '📦 版本',
|
|
667
677
|
'ctrl.version.installed': '本地版本:{v}',
|
|
668
678
|
'ctrl.version.latest': 'npm 最新:{v}',
|
|
669
679
|
'ctrl.version.unknown': '未知',
|
|
@@ -705,7 +715,7 @@ const DICT = {
|
|
|
705
715
|
'ctrl.seed.failed': '无法初始化话题 —— 请查看桥的日志。',
|
|
706
716
|
'ctrl.lang.state': '语言:{lang}\n可用:{list}\n切换:/lang en',
|
|
707
717
|
'ctrl.lang.auto': 'auto',
|
|
708
|
-
'ctrl.doctor.title': '诊断',
|
|
718
|
+
'ctrl.doctor.title': '🩺 诊断',
|
|
709
719
|
'ctrl.doctor.bridgePid': '桥 pid',
|
|
710
720
|
'ctrl.doctor.noPidFile': '没有文件',
|
|
711
721
|
'ctrl.doctor.bridgeAlive': '桥存活',
|
|
@@ -731,6 +741,8 @@ const DICT = {
|
|
|
731
741
|
'ctrl.logs.empty': '日志为空。',
|
|
732
742
|
'ctrl.logs.errors': '错误({shown}/{total})',
|
|
733
743
|
'ctrl.logs.title': '日志({shown}/{total})',
|
|
744
|
+
'ctrl.logs.fileCaption': 'bridge.log,{mb} MB —— 完整文件',
|
|
745
|
+
'ctrl.logs.noFileChannel': '这个桥接版本无法发送文件;请用 /logs 200。',
|
|
734
746
|
'ctrl.thoughts.title': '🧠 上一轮的推理({chars} 字符,几分钟后消失):',
|
|
735
747
|
'ctrl.thoughts.none': '上一轮没有保存推理过程。',
|
|
736
748
|
'ctrl.thoughts.lastAnswer': '上一轮的回答:',
|
package/package.json
CHANGED