dsh-tg-bridge 1.7.1 → 1.7.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/bridge.mjs +36 -8
- package/control.mjs +5 -2
- package/i18n.mjs +18 -12
- package/package.json +1 -1
- package/sync-runtime.mjs +37 -13
package/bridge.mjs
CHANGED
|
@@ -1229,8 +1229,11 @@ async function mediaPrompt(msgs, chatId, threadId, lang, opts = {}) {
|
|
|
1229
1229
|
let text = parts.filter(Boolean).join('\n\n');
|
|
1230
1230
|
// A steer cannot apply the vision overlay to a turn that is already running,
|
|
1231
1231
|
// so the model gets a path and an honest line instead of a silently
|
|
1232
|
-
// unreadable image.
|
|
1233
|
-
|
|
1232
|
+
// unreadable image. If the turn died while the file was being fetched, the
|
|
1233
|
+
// text is about to become a turn of its own — and there the image *is*
|
|
1234
|
+
// readable, so the disclaimer would be a lie.
|
|
1235
|
+
const liveNow = opts.stillRunning ? opts.stillRunning() : true;
|
|
1236
|
+
if (text && photo && opts.steer && liveNow) text += `\n\n${t(lang, 'prompt.photoMidTurn')}`;
|
|
1234
1237
|
if (text && caption) text += `\n\n${t(lang, 'prompt.note', { note: caption })}`;
|
|
1235
1238
|
return { text, extraArgs, profile };
|
|
1236
1239
|
}
|
|
@@ -1756,13 +1759,33 @@ function watchSteer(job, msg, text, thread, lang) {
|
|
|
1756
1759
|
async function steerMediaMessage(msgs, sessionId, key, thread, lang) {
|
|
1757
1760
|
const list = Array.isArray(msgs) ? msgs : [msgs];
|
|
1758
1761
|
const first = list[0];
|
|
1759
|
-
const
|
|
1762
|
+
const wasRunning = activeTurns.has(key);
|
|
1763
|
+
const built = await mediaPrompt(list, first.chat.id, thread, lang, {
|
|
1764
|
+
steer: true,
|
|
1765
|
+
stillRunning: () => activeTurns.has(key),
|
|
1766
|
+
});
|
|
1760
1767
|
if (!built.text) {
|
|
1761
1768
|
log('steer media produced no text; nothing injected');
|
|
1762
1769
|
return;
|
|
1763
1770
|
}
|
|
1764
|
-
if (
|
|
1765
|
-
|
|
1771
|
+
if (activeTurns.has(key)) {
|
|
1772
|
+
steerRunningTurn(first, built.text, sessionId, thread);
|
|
1773
|
+
return;
|
|
1774
|
+
}
|
|
1775
|
+
// Transcribing and downloading take seconds; the turn this addition was meant
|
|
1776
|
+
// for may already be gone. Writing the job anyway left the addition in the
|
|
1777
|
+
// directory until `watchSteer` noticed — a minute of silence for a voice note
|
|
1778
|
+
// that arrived half a second too late. The prepared text (transcript, file
|
|
1779
|
+
// path, caption) is already the whole request, so run it as its own turn.
|
|
1780
|
+
log(`steer media: turn ended during prep (was ${wasRunning ? 'running' : 'gone'}), delivering as a turn (${key})`);
|
|
1781
|
+
enqueue(key, () => handleMessage({
|
|
1782
|
+
chat: first.chat,
|
|
1783
|
+
from: first.from,
|
|
1784
|
+
message_id: 0,
|
|
1785
|
+
message_thread_id: thread || undefined,
|
|
1786
|
+
is_topic_message: thread > 0,
|
|
1787
|
+
text: built.text,
|
|
1788
|
+
}));
|
|
1766
1789
|
}
|
|
1767
1790
|
|
|
1768
1791
|
// ------------------------------------------------------------------ albums
|
|
@@ -1797,7 +1820,11 @@ async function deliverAlbum(msgs) {
|
|
|
1797
1820
|
const lang = resolveLang(state, key, first, config);
|
|
1798
1821
|
const sessionId = liveSessions.get(key) || state.sessions[key];
|
|
1799
1822
|
log(`album ${first.media_group_id}: ${msgs.length} item(s) in ${key}`);
|
|
1800
|
-
|
|
1823
|
+
// Decide at flush time, not at send time: the buffer holds the photos for up
|
|
1824
|
+
// to four seconds, and a turn that ended in that window must still get an
|
|
1825
|
+
// answer rather than a silent drop. `steerMediaMessage` re-checks on its own
|
|
1826
|
+
// and quotes the built prompt into a turn when the steered turn is gone.
|
|
1827
|
+
if (config.steerDuringTurn !== false && steerAvailable(profileOf(key)) && sessionId) {
|
|
1801
1828
|
try {
|
|
1802
1829
|
await steerMediaMessage(msgs, sessionId, key, thread, lang);
|
|
1803
1830
|
return;
|
|
@@ -2209,8 +2236,9 @@ async function main() {
|
|
|
2209
2236
|
return;
|
|
2210
2237
|
}
|
|
2211
2238
|
// Transcription and downloads take seconds; the update loop must not
|
|
2212
|
-
// wait for them
|
|
2213
|
-
//
|
|
2239
|
+
// wait for them. The turn may finish meanwhile, and `steerMediaMessage`
|
|
2240
|
+
// then runs the prepared text as a turn of its own instead of leaving
|
|
2241
|
+
// the voicemail in a directory nobody reads again.
|
|
2214
2242
|
ack(update.update_id);
|
|
2215
2243
|
const lang = resolveLang(state, queueKey, msg, config);
|
|
2216
2244
|
void steerMediaMessage(msg, sessionId, queueKey, thread, lang).catch((error) => {
|
package/control.mjs
CHANGED
|
@@ -470,7 +470,7 @@ export async function handleControl(ctx) {
|
|
|
470
470
|
const stats = sessionId ? sessionStats(sessionFile(join(DSH_HOME, 'sessions'), sessionId)) : null;
|
|
471
471
|
const title = sessionId ? state.titles?.[key] : '';
|
|
472
472
|
const lines = [t(lang, 'ctrl.status.head')];
|
|
473
|
-
lines.push(t(lang, 'ctrl.status.session', { id: sessionId
|
|
473
|
+
lines.push(t(lang, 'ctrl.status.session', { id: sessionId || t(lang, 'ctrl.session.none') }));
|
|
474
474
|
if (title) lines.push(t(lang, 'ctrl.status.title', { title }));
|
|
475
475
|
lines.push(t(lang, 'ctrl.status.profile', { name: activeProfile, route: `${head.provider}/${head.model}` }));
|
|
476
476
|
lines.push(t(lang, 'ctrl.status.thread', { name: ctx.threadId || t(lang, 'ctrl.status.threadDefault') }));
|
|
@@ -490,7 +490,10 @@ export async function handleControl(ctx) {
|
|
|
490
490
|
lines.push(t(lang, 'ctrl.status.lifetime', { n: stats.lifetimeTokens.toLocaleString('en-US') }));
|
|
491
491
|
}
|
|
492
492
|
if (stats?.turns) lines.push(t(lang, 'ctrl.status.steps', { n: stats.turns }));
|
|
493
|
-
lines.push(t(lang, 'ctrl.status.turns', {
|
|
493
|
+
lines.push(t(lang, 'ctrl.status.turns', {
|
|
494
|
+
n: active,
|
|
495
|
+
state: active > 0 ? t(lang, 'ctrl.status.running') : t(lang, 'ctrl.status.idle'),
|
|
496
|
+
}));
|
|
494
497
|
lines.push(t(lang, 'ctrl.status.notes', {
|
|
495
498
|
state: reasoningOf(state, config, key) ? t(lang, 'ctrl.status.on') : t(lang, 'ctrl.status.off'),
|
|
496
499
|
}));
|
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',
|
|
@@ -349,7 +351,9 @@ const DICT = {
|
|
|
349
351
|
'ctrl.status.contextNoWindow': 'Контекст: {now} токенов (окно неизвестно: укажи contextWindow в config.json)',
|
|
350
352
|
'ctrl.status.lifetime': 'Токенов за сессию: {n}',
|
|
351
353
|
'ctrl.status.steps': 'Ходов в сессии: {n}',
|
|
352
|
-
'ctrl.status.turns': '
|
|
354
|
+
'ctrl.status.turns': 'Агент работает: {state} ({n} ход(ов))',
|
|
355
|
+
'ctrl.status.running': 'да',
|
|
356
|
+
'ctrl.status.idle': 'нет',
|
|
353
357
|
'ctrl.status.notes': 'Заметки по ходу (💭 в прогрессе): {state}',
|
|
354
358
|
'ctrl.status.on': 'включены',
|
|
355
359
|
'ctrl.status.off': 'выключены',
|
|
@@ -363,7 +367,7 @@ const DICT = {
|
|
|
363
367
|
'ctrl.model.switched': 'Модель {name} → {model}{desktop}. Действует со следующего хода.',
|
|
364
368
|
'ctrl.model.withDesktop': ', desktop → {model}',
|
|
365
369
|
'ctrl.sessions.empty': 'Сессий не нашёл.',
|
|
366
|
-
'ctrl.sessions.title': 'Последние сессии:',
|
|
370
|
+
'ctrl.sessions.title': '🗂 Последние сессии:',
|
|
367
371
|
'ctrl.sessions.untitled': '(без названия)',
|
|
368
372
|
'ctrl.resume.usage': 'Использование: /resume <id> (/sessions — список)',
|
|
369
373
|
'ctrl.resume.done': 'Эта ветка продолжит сессию {id}.',
|
|
@@ -395,7 +399,7 @@ const DICT = {
|
|
|
395
399
|
'ctrl.soul.title': 'Персона ({path}):\n\n{text}',
|
|
396
400
|
'ctrl.soul.empty': 'Персона пуста. Задать: /soul <text>\nФайл: {path}',
|
|
397
401
|
'ctrl.soul.saved': 'Персона обновлена в ~/.dsh/AGENTS.md. Применяется в новых сессиях.',
|
|
398
|
-
'ctrl.version.title': 'Версии',
|
|
402
|
+
'ctrl.version.title': '📦 Версии',
|
|
399
403
|
'ctrl.version.installed': 'Установлено здесь: {v}',
|
|
400
404
|
'ctrl.version.latest': 'Последняя на npm: {v}',
|
|
401
405
|
'ctrl.version.unknown': 'неизвестно',
|
|
@@ -437,7 +441,7 @@ const DICT = {
|
|
|
437
441
|
'ctrl.seed.failed': 'Не смог засеять тему — смотри лог моста.',
|
|
438
442
|
'ctrl.lang.state': 'Язык: {lang}\nДоступно: {list}\nПереключить: /lang en',
|
|
439
443
|
'ctrl.lang.auto': 'auto',
|
|
440
|
-
'ctrl.doctor.title': 'Диагностика',
|
|
444
|
+
'ctrl.doctor.title': '🩺 Диагностика',
|
|
441
445
|
'ctrl.doctor.bridgePid': 'Мост pid',
|
|
442
446
|
'ctrl.doctor.noPidFile': 'нет файла',
|
|
443
447
|
'ctrl.doctor.bridgeAlive': 'Мост жив',
|
|
@@ -617,7 +621,9 @@ const DICT = {
|
|
|
617
621
|
'ctrl.status.contextNoWindow': '上下文:{now} 个 token(窗口未知:在 config.json 里设置 contextWindow)',
|
|
618
622
|
'ctrl.status.lifetime': '本会话累计 token:{n}',
|
|
619
623
|
'ctrl.status.steps': '会话中的轮次:{n}',
|
|
620
|
-
'ctrl.status.turns': '
|
|
624
|
+
'ctrl.status.turns': '代理运行中:{state}({n} 个任务)',
|
|
625
|
+
'ctrl.status.running': '是',
|
|
626
|
+
'ctrl.status.idle': '否',
|
|
621
627
|
'ctrl.status.notes': '工作记录(进度中的 💭):{state}',
|
|
622
628
|
'ctrl.status.on': '开',
|
|
623
629
|
'ctrl.status.off': '关',
|
|
@@ -631,7 +637,7 @@ const DICT = {
|
|
|
631
637
|
'ctrl.model.switched': '模型 {name} → {model}{desktop}。下一轮生效。',
|
|
632
638
|
'ctrl.model.withDesktop': ',desktop → {model}',
|
|
633
639
|
'ctrl.sessions.empty': '没有找到会话。',
|
|
634
|
-
'ctrl.sessions.title': '最近的会话:',
|
|
640
|
+
'ctrl.sessions.title': '🗂 最近的会话:',
|
|
635
641
|
'ctrl.sessions.untitled': '(无标题)',
|
|
636
642
|
'ctrl.resume.usage': '用法:/resume <id> (/sessions 查看列表)',
|
|
637
643
|
'ctrl.resume.done': '本话题将接着使用会话 {id}。',
|
|
@@ -663,7 +669,7 @@ const DICT = {
|
|
|
663
669
|
'ctrl.soul.title': '人格({path}):\n\n{text}',
|
|
664
670
|
'ctrl.soul.empty': '人格为空。设置:/soul <文本>\n文件:{path}',
|
|
665
671
|
'ctrl.soul.saved': '人格已更新到 ~/.dsh/AGENTS.md。对新会话生效。',
|
|
666
|
-
'ctrl.version.title': '版本',
|
|
672
|
+
'ctrl.version.title': '📦 版本',
|
|
667
673
|
'ctrl.version.installed': '本地版本:{v}',
|
|
668
674
|
'ctrl.version.latest': 'npm 最新:{v}',
|
|
669
675
|
'ctrl.version.unknown': '未知',
|
|
@@ -705,7 +711,7 @@ const DICT = {
|
|
|
705
711
|
'ctrl.seed.failed': '无法初始化话题 —— 请查看桥的日志。',
|
|
706
712
|
'ctrl.lang.state': '语言:{lang}\n可用:{list}\n切换:/lang en',
|
|
707
713
|
'ctrl.lang.auto': 'auto',
|
|
708
|
-
'ctrl.doctor.title': '诊断',
|
|
714
|
+
'ctrl.doctor.title': '🩺 诊断',
|
|
709
715
|
'ctrl.doctor.bridgePid': '桥 pid',
|
|
710
716
|
'ctrl.doctor.noPidFile': '没有文件',
|
|
711
717
|
'ctrl.doctor.bridgeAlive': '桥存活',
|
package/package.json
CHANGED
package/sync-runtime.mjs
CHANGED
|
@@ -1,20 +1,44 @@
|
|
|
1
|
-
// Copy
|
|
2
|
-
// keeping a timestamped backup of what it replaces.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// Copy the runtime files of this checkout into the live bridge directory,
|
|
2
|
+
// keeping a timestamped backup of what it replaces.
|
|
3
|
+
//
|
|
4
|
+
// node sync-runtime.mjs # repo -> ~/.dsh/tg-bridge
|
|
5
|
+
// node sync-runtime.mjs --dir X # repo -> X
|
|
6
|
+
//
|
|
7
|
+
// Written in Node, not PowerShell: the files are UTF-8 with Cyrillic, and
|
|
8
|
+
// Set-Content would mangle them. The version in package.json comes along too —
|
|
9
|
+
// `/version` reads it, and a module-only sync would leave it describing the
|
|
10
|
+
// previous release.
|
|
11
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync } from 'node:fs';
|
|
12
|
+
import { homedir } from 'node:os';
|
|
13
|
+
import { dirname, join } from 'node:path';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
|
|
16
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
const flag = process.argv.indexOf('--dir');
|
|
18
|
+
const target = flag > -1 && process.argv[flag + 1]
|
|
19
|
+
? process.argv[flag + 1]
|
|
20
|
+
: join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'tg-bridge');
|
|
21
|
+
|
|
22
|
+
if (!existsSync(target)) mkdirSync(target, { recursive: true });
|
|
6
23
|
|
|
7
|
-
const repo = 'C:\\Users\\bistr\\Projects\\dsh-tg-bridge-oss';
|
|
8
|
-
const run = 'C:\\Users\\bistr\\.dsh\\tg-bridge';
|
|
9
24
|
const stamp = new Date().toISOString().replace(/[:.]/g, '').slice(0, 15);
|
|
10
|
-
const
|
|
25
|
+
const names = readdirSync(here).filter((name) => name.endsWith('.mjs') || name === 'package.json');
|
|
11
26
|
let copied = 0;
|
|
12
27
|
|
|
13
|
-
for (const
|
|
14
|
-
|
|
28
|
+
for (const name of names) {
|
|
29
|
+
if (name === 'sync-runtime.mjs') continue;
|
|
30
|
+
const to = join(target, name);
|
|
15
31
|
if (existsSync(to)) copyFileSync(to, `${to}.bak-${stamp}`);
|
|
16
|
-
copyFileSync(join(
|
|
32
|
+
copyFileSync(join(here, name), to);
|
|
17
33
|
copied += 1;
|
|
18
34
|
}
|
|
19
|
-
|
|
20
|
-
|
|
35
|
+
|
|
36
|
+
const version = (() => {
|
|
37
|
+
try {
|
|
38
|
+
return JSON.parse(readFileSync(join(target, 'package.json'), 'utf8')).version;
|
|
39
|
+
} catch {
|
|
40
|
+
return 'unknown';
|
|
41
|
+
}
|
|
42
|
+
})();
|
|
43
|
+
console.log(`synced ${copied} files into ${target} (version ${version}, backup stamp ${stamp})`);
|
|
44
|
+
console.log('restart the bridge to load them: /restart confirm in Telegram');
|