dsh-tg-bridge 1.7.3 → 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 +44 -20
- package/i18n.mjs +12 -6
- 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);
|
|
@@ -1126,8 +1152,24 @@ export async function handleControl(ctx) {
|
|
|
1126
1152
|
|
|
1127
1153
|
case '/logs': {
|
|
1128
1154
|
// `/logs` — meaningful events, `/logs 100` — more, `/logs <text>` —
|
|
1129
|
-
// 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.
|
|
1130
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
|
+
}
|
|
1131
1173
|
let lines = [];
|
|
1132
1174
|
try {
|
|
1133
1175
|
lines = readFileSync(file, 'utf8').split(/\r?\n/).filter(Boolean);
|
|
@@ -1138,30 +1180,12 @@ export async function handleControl(ctx) {
|
|
|
1138
1180
|
const numeric = Number(arg);
|
|
1139
1181
|
const count = Number.isInteger(numeric) && numeric > 0 ? Math.min(numeric, 200) : 30;
|
|
1140
1182
|
const filter = Number.isInteger(numeric) ? '' : (arg || '').trim();
|
|
1141
|
-
|
|
1142
|
-
// Delivery chatter ("in 123", "sent chat=...") answers nothing when the
|
|
1143
|
-
// question is "what did the agent do". It stays in the file for delivery
|
|
1144
|
-
// debugging but is hidden from the chat view.
|
|
1145
|
-
const isChatter = (line) =>
|
|
1146
|
-
/\bsent chat=/.test(line)
|
|
1147
|
-
|| /\bin \d+ /.test(line)
|
|
1148
|
-
|| /bridge started|bot @|replaying \d+ pending|topic \d+ (?:seeded|logged)/.test(line);
|
|
1149
|
-
|
|
1150
|
-
let pool;
|
|
1151
|
-
if (filter === 'errors') {
|
|
1152
|
-
pool = lines.filter((line) => /turn failed|ОШИБКА|error|poll error|409|Conflict|quota|AUTH/i.test(line));
|
|
1153
|
-
} else if (filter) {
|
|
1154
|
-
const needle = filter.toLowerCase();
|
|
1155
|
-
pool = lines.filter((line) => line.toLowerCase().includes(needle));
|
|
1156
|
-
} else {
|
|
1157
|
-
pool = lines.filter((line) => !isChatter(line));
|
|
1158
|
-
}
|
|
1183
|
+
const { pool, tail } = filterLogLines(lines, filter, count);
|
|
1159
1184
|
|
|
1160
1185
|
if (pool.length === 0) {
|
|
1161
1186
|
say(filter ? t(lang, 'ctrl.logs.noMatch', { filter }) : t(lang, 'ctrl.logs.empty'));
|
|
1162
1187
|
return true;
|
|
1163
1188
|
}
|
|
1164
|
-
const tail = pool.slice(-count);
|
|
1165
1189
|
const header = filter === 'errors'
|
|
1166
1190
|
? t(lang, 'ctrl.logs.errors', { shown: tail.length, total: pool.length })
|
|
1167
1191
|
: t(lang, 'ctrl.logs.title', { shown: tail.length, total: pool.length });
|
package/i18n.mjs
CHANGED
|
@@ -81,8 +81,8 @@ 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': 'Agent running: {state} ({n} turn(s))',
|
|
85
|
-
'ctrl.status.running': 'yes',
|
|
84
|
+
'ctrl.status.turns': 'Agent running: {state} ({n} turn(s))',
|
|
85
|
+
'ctrl.status.running': 'yes',
|
|
86
86
|
'ctrl.status.idle': 'no',
|
|
87
87
|
'ctrl.status.notes': 'Working notes (💭 in progress): {state}',
|
|
88
88
|
'ctrl.status.on': 'on',
|
|
@@ -197,6 +197,8 @@ const DICT = {
|
|
|
197
197
|
'ctrl.logs.empty': 'The log is empty.',
|
|
198
198
|
'ctrl.logs.errors': 'Errors ({shown} of {total})',
|
|
199
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.',
|
|
200
202
|
'ctrl.thoughts.title': '🧠 Reasoning of the last turn ({chars} chars, kept for a few minutes):',
|
|
201
203
|
'ctrl.thoughts.none': 'The last turn stored no reasoning plan.',
|
|
202
204
|
'ctrl.thoughts.lastAnswer': 'What the last turn answered:',
|
|
@@ -351,8 +353,8 @@ const DICT = {
|
|
|
351
353
|
'ctrl.status.contextNoWindow': 'Контекст: {now} токенов (окно неизвестно: укажи contextWindow в config.json)',
|
|
352
354
|
'ctrl.status.lifetime': 'Токенов за сессию: {n}',
|
|
353
355
|
'ctrl.status.steps': 'Ходов в сессии: {n}',
|
|
354
|
-
'ctrl.status.turns': 'Агент работает: {state} ({n} ход(ов))',
|
|
355
|
-
'ctrl.status.running': 'да',
|
|
356
|
+
'ctrl.status.turns': 'Агент работает: {state} ({n} ход(ов))',
|
|
357
|
+
'ctrl.status.running': 'да',
|
|
356
358
|
'ctrl.status.idle': 'нет',
|
|
357
359
|
'ctrl.status.notes': 'Заметки по ходу (💭 в прогрессе): {state}',
|
|
358
360
|
'ctrl.status.on': 'включены',
|
|
@@ -467,6 +469,8 @@ const DICT = {
|
|
|
467
469
|
'ctrl.logs.empty': 'Лог пуст.',
|
|
468
470
|
'ctrl.logs.errors': 'Ошибки ({shown} из {total})',
|
|
469
471
|
'ctrl.logs.title': 'Лог ({shown} из {total})',
|
|
472
|
+
'ctrl.logs.fileCaption': 'bridge.log, {mb} МБ — файл целиком',
|
|
473
|
+
'ctrl.logs.noFileChannel': 'Эта сборка моста не умеет отправлять файлы; используй /logs 200.',
|
|
470
474
|
'ctrl.thoughts.title': '🧠 Рассуждения последнего хода ({chars} символов, повисят несколько минут):',
|
|
471
475
|
'ctrl.thoughts.none': 'В последнем ходе не сохранилось плана рассуждений.',
|
|
472
476
|
'ctrl.thoughts.lastAnswer': 'Последний ход ответил так:',
|
|
@@ -621,8 +625,8 @@ const DICT = {
|
|
|
621
625
|
'ctrl.status.contextNoWindow': '上下文:{now} 个 token(窗口未知:在 config.json 里设置 contextWindow)',
|
|
622
626
|
'ctrl.status.lifetime': '本会话累计 token:{n}',
|
|
623
627
|
'ctrl.status.steps': '会话中的轮次:{n}',
|
|
624
|
-
'ctrl.status.turns': '代理运行中:{state}({n} 个任务)',
|
|
625
|
-
'ctrl.status.running': '是',
|
|
628
|
+
'ctrl.status.turns': '代理运行中:{state}({n} 个任务)',
|
|
629
|
+
'ctrl.status.running': '是',
|
|
626
630
|
'ctrl.status.idle': '否',
|
|
627
631
|
'ctrl.status.notes': '工作记录(进度中的 💭):{state}',
|
|
628
632
|
'ctrl.status.on': '开',
|
|
@@ -737,6 +741,8 @@ const DICT = {
|
|
|
737
741
|
'ctrl.logs.empty': '日志为空。',
|
|
738
742
|
'ctrl.logs.errors': '错误({shown}/{total})',
|
|
739
743
|
'ctrl.logs.title': '日志({shown}/{total})',
|
|
744
|
+
'ctrl.logs.fileCaption': 'bridge.log,{mb} MB —— 完整文件',
|
|
745
|
+
'ctrl.logs.noFileChannel': '这个桥接版本无法发送文件;请用 /logs 200。',
|
|
740
746
|
'ctrl.thoughts.title': '🧠 上一轮的推理({chars} 字符,几分钟后消失):',
|
|
741
747
|
'ctrl.thoughts.none': '上一轮没有保存推理过程。',
|
|
742
748
|
'ctrl.thoughts.lastAnswer': '上一轮的回答:',
|
package/package.json
CHANGED