dsh-tg-bridge 1.7.1 → 1.7.2

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 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
- if (text && photo && opts.steer) text += `\n\n${t(lang, 'prompt.photoMidTurn')}`;
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 built = await mediaPrompt(list, first.chat.id, thread, lang, { steer: true });
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 (!activeTurns.has(key)) log(`steer media: turn ended during prep, job will re-queue (${key})`);
1765
- steerRunningTurn(first, built.text, sessionId, thread);
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
- if (config.steerDuringTurn !== false && steerAvailable(profileOf(key)) && activeTurns.has(key) && sessionId) {
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, and the turn may even finish meanwhile — the steer
2213
- // watcher then turns the prepared text into a turn of its own.
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-tg-bridge",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "Telegram bridge for DeepSeek Harness: text, voice, photos and project-per-topic sessions without opening the desktop app",
5
5
  "type": "module",
6
6
  "main": "plugin-bridge.mjs",
package/sync-runtime.mjs CHANGED
@@ -1,20 +1,44 @@
1
- // Copy every runtime module from the repo into the live bridge directory,
2
- // keeping a timestamped backup of what it replaces. Node, not PowerShell: the
3
- // files are UTF-8 with Cyrillic, and Set-Content would mangle them.
4
- import { copyFileSync, existsSync, mkdirSync, readdirSync } from 'node:fs';
5
- import { join } from 'node:path';
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 files = readdirSync(repo).filter((f) => f.endsWith('.mjs'));
25
+ const names = readdirSync(here).filter((name) => name.endsWith('.mjs') || name === 'package.json');
11
26
  let copied = 0;
12
27
 
13
- for (const file of files) {
14
- const to = join(run, file);
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(repo, file), to);
32
+ copyFileSync(join(here, name), to);
17
33
  copied += 1;
18
34
  }
19
- mkdirSync(run, { recursive: true });
20
- console.log(`synced ${copied} modules from the repo to the runtime (backup stamp ${stamp})`);
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');