dsh-tg-bridge 1.5.4 → 1.7.0
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/README.md +67 -7
- package/albums.mjs +37 -0
- package/bot-menu.mjs +27 -15
- package/bridge.mjs +453 -170
- package/cli-args.mjs +17 -0
- package/cli.mjs +1 -1
- package/control.mjs +1258 -949
- package/i18n.mjs +560 -5
- package/immediate.mjs +14 -36
- package/media-text.mjs +33 -0
- package/package.json +8 -3
- package/profiles.mjs +78 -0
- package/thoughts.mjs +93 -0
package/README.md
CHANGED
|
@@ -11,7 +11,8 @@ blocks.
|
|
|
11
11
|
|
|
12
12
|
- **Text**: a regular task goes to the agent, the answer comes back in the same topic.
|
|
13
13
|
- **Voice**: local faster-whisper, the transcript is shown before the answer.
|
|
14
|
-
- **Photos**:
|
|
14
|
+
- **Photos**: the turn's own model reads them through `read_image`, text and UI
|
|
15
|
+
included; no second model is needed (a vision overlay stays opt-in).
|
|
15
16
|
- **Project per topic**: `/cd my-app`, and all turns run from that directory.
|
|
16
17
|
- **Goal and checklist per topic**: `/goal`, `/task`; both survive restarts and are prepended to every turn.
|
|
17
18
|
- **Live progress**: "⏳ Working..." with steps, a timer and the cache hit rate at the end.
|
|
@@ -53,7 +54,7 @@ can be listed next to them:
|
|
|
53
54
|
- Topic language: `/lang en|ru|zh`; stored in `state.json` and survives a restart.
|
|
54
55
|
- A new user gets the language from the Telegram `language_code`; anything that is not `ru`/`zh` → `en`.
|
|
55
56
|
- Translated so far: menus, the start message, turn status, errors, `/cd`, `/new`, `/stop`, `/lang`,
|
|
56
|
-
the reply to an unknown command. Long reports (`/status`, `/sessions`, `/
|
|
57
|
+
the reply to an unknown command. Long reports (`/status`, `/sessions`, `/model` and similar)
|
|
57
58
|
are still in Russian, that is the next pass.
|
|
58
59
|
|
|
59
60
|
## Installation
|
|
@@ -98,7 +99,8 @@ Optional provider settings live in `config.json`:
|
|
|
98
99
|
|---|---|
|
|
99
100
|
| `providerKeys` | extra env var names to pass to a turn, read from `~/.dsh/.credentials.yaml`; default `[]` |
|
|
100
101
|
| `pricesUrl` | public model page for `/prices`; default `""` uses models.dev only |
|
|
101
|
-
| `vision.patch` | overlay for photo turns; default `""`
|
|
102
|
+
| `vision.patch` | opt-in overlay profile for photo turns; default `""` — the turn's own model reads images |
|
|
103
|
+
| `vision.enabled` | set `true` to run photo turns on `vision.patch` instead of the topic profile |
|
|
102
104
|
| `fallbackModels` | free-model fallbacks; default `[]` |
|
|
103
105
|
|
|
104
106
|
Get your id from [@userinfobot](https://t.me/userinfobot), the token from
|
|
@@ -144,13 +146,13 @@ Error replies end with a code, which tells you what to fix:
|
|
|
144
146
|
|
|
145
147
|
| Code | Meaning |
|
|
146
148
|
|---|---|
|
|
147
|
-
| `INSUFFICIENT_QUOTA` | provider balance is empty: top up or stay on free models (`/prices`, `/
|
|
149
|
+
| `INSUFFICIENT_QUOTA` | provider balance is empty: top up or stay on free models (`/prices`, `/model`) |
|
|
148
150
|
| `TG_CONFLICT` | a second process is polling the same bot: `/doctor`, then `/restart` |
|
|
149
151
|
| `MISSING_CREDENTIAL` | no provider key in the profile: add it in the DSH app |
|
|
150
152
|
| `NO_DSH_CLI` | DeepSeek Harness CLI not found: check the app installation |
|
|
151
153
|
| `NETWORK` | no network to the provider: retry, check VPN/DNS |
|
|
152
154
|
| `SANDBOX_DENY` | DSH denied access to a file or directory: check the project path and permissions |
|
|
153
|
-
| `UNKNOWN_MODEL` | the model from the config is unavailable: `/
|
|
155
|
+
| `UNKNOWN_MODEL` | the model from the config is unavailable: `/model` lists the working ones |
|
|
154
156
|
| `EMPTY_RESPONSE` | the model returned nothing: retry or switch model (`/model`) |
|
|
155
157
|
| `TURN_FAILED` | cause not recognized: `/doctor` and `/logs errors` |
|
|
156
158
|
|
|
@@ -161,6 +163,9 @@ Send the bot:
|
|
|
161
163
|
| Command | Expected |
|
|
162
164
|
|---|---|
|
|
163
165
|
| `/doctor` | report: pid, Telegram, disk, directory, session |
|
|
166
|
+
| `/version` | bridge version, the latest on npm, bridge directory |
|
|
167
|
+
| `/update` | says whether a newer release exists (`/update confirm` installs it) |
|
|
168
|
+
| `/thoughts` | the last turn's reasoning, deleted after a few minutes |
|
|
164
169
|
| `/help` | commands grouped by category |
|
|
165
170
|
| `/cd my-app` | topic bound to the project |
|
|
166
171
|
| `/prices` | model prices and the cost of the current one |
|
|
@@ -171,10 +176,12 @@ Send the bot:
|
|
|
171
176
|
Work: /cd · /new · /stop · /send · /seed
|
|
172
177
|
Goals: /goal · /task
|
|
173
178
|
Sessions: /status · /sessions · /resume
|
|
174
|
-
Models: /
|
|
175
|
-
|
|
179
|
+
Models: /model · /model <id> · /prices
|
|
180
|
+
Profiles: /profile · /profile <name> · /profile new <name> from <template>
|
|
181
|
+
Extensions: /skills · /plugins · /soul
|
|
176
182
|
Diagnostics: /doctor · /logs [errors|N|text]
|
|
177
183
|
Service: /app · /restart · /help
|
|
184
|
+
Display: /lang · /reasoning on|off
|
|
178
185
|
```
|
|
179
186
|
|
|
180
187
|
## How it works
|
|
@@ -200,6 +207,35 @@ plugin hands it to the live agent on its next step, and the agent immediately re
|
|
|
200
207
|
line in the chat: what it is doing now and where it put the addition. If the agent stays silent
|
|
201
208
|
for 90 seconds, the bridge writes one neutral line itself so there is no silence.
|
|
202
209
|
|
|
210
|
+
Attachments work the same way. A voice note is transcribed first and its transcript is echoed in
|
|
211
|
+
the chat, then the text is steered into the running turn; a photo or a file is downloaded to a
|
|
212
|
+
local path and that path is steered, exactly as an idle turn would hand it over.
|
|
213
|
+
|
|
214
|
+
What each kind of attachment becomes inside a running turn:
|
|
215
|
+
|
|
216
|
+
| Sent | Inside the turn |
|
|
217
|
+
|---|---|
|
|
218
|
+
| voice note, audio file, audio sent as a document | transcript, echoed as `🎤 …` before the steer |
|
|
219
|
+
| small text file (`.md`, `.json`, `.csv`, `.py`, `.log`, … up to 60 KB) | the content itself between `<file>` markers — no tool call needed |
|
|
220
|
+
| PDF, archive, binary, anything bigger | its local path under `~/.dsh/tg-bridge/inbox/` |
|
|
221
|
+
| video, video note, animation | its path; the agent can pull frames or sound out with ffmpeg |
|
|
222
|
+
| photo | its path plus one honest line; the turn reads it with `read_image`, and says so in one line if it cannot |
|
|
223
|
+
|
|
224
|
+
A caption does not turn the attachment into a text-only message: it is folded into the same
|
|
225
|
+
hand-over, so "why did this fail" plus a `.log` file arrives as one steer.
|
|
226
|
+
|
|
227
|
+
An album is one request, not ten. Telegram delivers it as one update per file, all sharing a
|
|
228
|
+
`media_group_id`; the bridge collects the group (1.2 s of quiet after the last item, at most
|
|
229
|
+
4 s) and hands it over once — one steer into a running turn, one turn when the topic is idle.
|
|
230
|
+
|
|
231
|
+
### When a turn hits the time ceiling
|
|
232
|
+
|
|
233
|
+
`turnTimeoutMs` (default 30 min, this install 75) is a ceiling, not a target: if a turn reaches
|
|
234
|
+
it, the bridge stops it with `⏱` instead of letting one runaway loop own the topic for hours.
|
|
235
|
+
Nothing is lost — the session and every file the turn produced stay in place — so the message
|
|
236
|
+
carries **⏵ Continue**, which asks the agent to check the state and go on from where it stopped.
|
|
237
|
+
That is deliberately not the same as **Retry**, which would redo the whole task from the start.
|
|
238
|
+
|
|
203
239
|
This needs the plugin from this repository:
|
|
204
240
|
|
|
205
241
|
```bash
|
|
@@ -231,6 +267,30 @@ message shows the last two as `💭` lines. The command needs no ids: it falls b
|
|
|
231
267
|
newest turn's thought file, because tool shells do not inherit the bridge environment.
|
|
232
268
|
`--thought` never sends a Telegram message on its own.
|
|
233
269
|
|
|
270
|
+
`/reasoning` is the switch for the whole mechanism. It is on by default: every turn carries a
|
|
271
|
+
short instruction to leave one line at each decision point (task clear, cause found, risky
|
|
272
|
+
change, result checked). `/reasoning off` drops the instruction and the `💭` lines for that
|
|
273
|
+
topic — useful when the step list is all you want. The setting lives in `state.json` per topic,
|
|
274
|
+
so a chatty research topic and a terse deploy topic can differ.
|
|
275
|
+
|
|
276
|
+
### Profiles per topic
|
|
277
|
+
|
|
278
|
+
The desktop app lets you build several profiles for different kinds of work, each with its own
|
|
279
|
+
plugin set and model. The same switch works from a topic:
|
|
280
|
+
|
|
281
|
+
```
|
|
282
|
+
/profile current profile, available ones, hints
|
|
283
|
+
/profile research run this topic's turns on another profile
|
|
284
|
+
/profile new research from web
|
|
285
|
+
create a profile from a shipped template and bind it
|
|
286
|
+
/profile default back to the install default
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
A new profile is written by `dsh <name> --from-default-profile <template> --dump-config`, so
|
|
290
|
+
nothing boots and no plugin is loaded at creation time; dependencies are installed by the
|
|
291
|
+
profile's first turn. The binding is per topic: `/model` then edits that profile's model, and
|
|
292
|
+
`/plugins` manages that profile's rows.
|
|
293
|
+
|
|
234
294
|
### Goals and tasks
|
|
235
295
|
|
|
236
296
|
A topic carries its own goal and checklist, so the aim survives `/new`, a
|
package/albums.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Album batching.
|
|
2
|
+
//
|
|
3
|
+
// Telegram delivers an album as one update per file, a few hundred ms apart,
|
|
4
|
+
// all sharing a `media_group_id`. Buffering them by that id turns "ten photos"
|
|
5
|
+
// into one hand-over instead of ten steers or ten turns.
|
|
6
|
+
//
|
|
7
|
+
// The wait is quiet-based: it restarts with each new item so a slow upload is
|
|
8
|
+
// not cut off, and it is capped by `maxMs` so one stuck item cannot hold the
|
|
9
|
+
// batch forever.
|
|
10
|
+
|
|
11
|
+
export function createAlbumBuffer({ quietMs = 1200, maxMs = 4000, onFlush } = {}) {
|
|
12
|
+
if (typeof onFlush !== 'function') throw new Error('createAlbumBuffer needs onFlush');
|
|
13
|
+
const groups = new Map();
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
/** Add one item to its group; returns how long until the group flushes. */
|
|
17
|
+
push(key, item, now = Date.now()) {
|
|
18
|
+
const entry = groups.get(key) || { items: [], timer: null, started: now };
|
|
19
|
+
entry.items.push(item);
|
|
20
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
21
|
+
const left = maxMs - (now - entry.started);
|
|
22
|
+
const wait = Math.max(0, Math.min(quietMs, left));
|
|
23
|
+
entry.timer = setTimeout(() => {
|
|
24
|
+
if (groups.get(key) === entry) groups.delete(key);
|
|
25
|
+
onFlush(entry.items, key);
|
|
26
|
+
}, wait);
|
|
27
|
+
entry.timer.unref?.();
|
|
28
|
+
groups.set(key, entry);
|
|
29
|
+
return wait;
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/** Groups still collecting; 0 means nothing is pending. */
|
|
33
|
+
pending() {
|
|
34
|
+
return groups.size;
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
package/bot-menu.mjs
CHANGED
|
@@ -38,19 +38,23 @@ const COMMANDS = [
|
|
|
38
38
|
{ command: 'seed', description: 'Засеять пустую тему текстом и закрепить' },
|
|
39
39
|
{ command: 'goal', description: 'Цель темы: /goal <текст>, /goal done' },
|
|
40
40
|
{ command: 'task', description: 'Задачи: /task <текст>, /task done <n>' },
|
|
41
|
-
{ command: 'sessions', description: '
|
|
42
|
-
{ command: 'resume', description: 'Продолжить
|
|
43
|
-
{ command: '
|
|
44
|
-
{ command: 'model', description: 'Сменить модель: /model <id>' },
|
|
41
|
+
{ command: 'sessions', description: 'Список сессий темы' },
|
|
42
|
+
{ command: 'resume', description: 'Продолжить сессию: /resume <id>' },
|
|
43
|
+
{ command: 'model', description: 'Показать или сменить: /model, /model <id>' },
|
|
45
44
|
{ command: 'skills', description: 'Скиллы: список или текст одного' },
|
|
46
45
|
{ command: 'soul', description: 'Персона: показать или задать' },
|
|
47
46
|
{ command: 'plugins', description: 'Список и управление: add/remove/disable/enable' },
|
|
48
|
-
{ command: 'app', description: '
|
|
47
|
+
{ command: 'app', description: 'Приложение DSH, не мост: /app restart confirm' },
|
|
49
48
|
{ command: 'restart', description: 'Перезапуск моста: /restart confirm' },
|
|
50
49
|
{ command: 'doctor', description: 'Диагностика: мост, сеть, диск, каталог, сессия' },
|
|
51
50
|
{ command: 'logs', description: 'Хвост лога моста: /logs 50 или /logs TG_NET' },
|
|
52
51
|
{ command: 'help', description: 'Все команды и подсказки' },
|
|
53
52
|
{ command: 'lang', description: 'Язык интерфейса: en, ru, zh' },
|
|
53
|
+
{ command: 'reasoning', description: 'Заметки по ходу: /reasoning on|off' },
|
|
54
|
+
{ command: 'profile', description: 'Профиль темы: /profile <имя>, /profile new' },
|
|
55
|
+
{ command: 'thoughts', description: 'Рассуждения последнего хода (исчезает)' },
|
|
56
|
+
{ command: 'version', description: 'Версия моста и последняя на npm' },
|
|
57
|
+
{ command: 'update', description: 'Обновить мост из npm: /update confirm' },
|
|
54
58
|
];
|
|
55
59
|
|
|
56
60
|
/** English menu (language_code: en). Same commands, translated descriptions. */
|
|
@@ -64,19 +68,23 @@ const COMMANDS_EN = [
|
|
|
64
68
|
{ command: 'seed', description: 'Seed an empty topic with text and pin it' },
|
|
65
69
|
{ command: 'goal', description: 'Topic goal: /goal <text>, /goal done' },
|
|
66
70
|
{ command: 'task', description: 'Checklist: /task <text>, /task done <n>' },
|
|
67
|
-
{ command: 'sessions', description: '
|
|
68
|
-
{ command: 'resume', description: 'Continue a session
|
|
69
|
-
{ command: '
|
|
70
|
-
{ command: 'model', description: 'Show or switch the model' },
|
|
71
|
+
{ command: 'sessions', description: 'This topic\u2019s sessions' },
|
|
72
|
+
{ command: 'resume', description: 'Continue a session: /resume <id>' },
|
|
73
|
+
{ command: 'model', description: 'Show or switch: /model, /model <id>' },
|
|
71
74
|
{ command: 'skills', description: 'Installed skills' },
|
|
72
75
|
{ command: 'soul', description: 'Agent persona' },
|
|
73
76
|
{ command: 'plugins', description: 'List and manage: add/remove/disable/enable' },
|
|
74
|
-
{ command: 'app', description: '
|
|
77
|
+
{ command: 'app', description: 'DSH desktop app (not the bridge)' },
|
|
75
78
|
{ command: 'restart', description: 'Restart the bridge: /restart confirm' },
|
|
76
79
|
{ command: 'doctor', description: 'Diagnostics: bridge, network, disk, directory, session' },
|
|
77
80
|
{ command: 'logs', description: 'Bridge log tail: /logs 50 or /logs TG_NET' },
|
|
78
81
|
{ command: 'help', description: 'All commands and hints' },
|
|
79
82
|
{ command: 'lang', description: 'Interface language: en, ru, zh' },
|
|
83
|
+
{ command: 'reasoning', description: 'Working notes: /reasoning on|off' },
|
|
84
|
+
{ command: 'profile', description: 'Topic profile: /profile <name>, /profile new' },
|
|
85
|
+
{ command: 'thoughts', description: 'Reasoning of the last turn (self-deleting)' },
|
|
86
|
+
{ command: 'version', description: 'Bridge version and the latest on npm' },
|
|
87
|
+
{ command: 'update', description: 'Update the bridge from npm: /update confirm' },
|
|
80
88
|
];
|
|
81
89
|
|
|
82
90
|
/** Chinese menu (language_code: zh-hans). */
|
|
@@ -90,19 +98,23 @@ const COMMANDS_ZH = [
|
|
|
90
98
|
{ command: 'seed', description: '用文本初始化空话题并置顶' },
|
|
91
99
|
{ command: 'goal', description: '本话题目标:/goal <文本>、/goal done' },
|
|
92
100
|
{ command: 'task', description: '任务清单:/task <文本>、/task done <n>' },
|
|
93
|
-
{ command: 'sessions', description: '
|
|
94
|
-
{ command: 'resume', description: '
|
|
95
|
-
{ command: '
|
|
96
|
-
{ command: 'model', description: '查看或切换模型' },
|
|
101
|
+
{ command: 'sessions', description: '本主题的会话列表' },
|
|
102
|
+
{ command: 'resume', description: '继续会话:/resume <id>' },
|
|
103
|
+
{ command: 'model', description: '查看或切换:/model, /model <id>' },
|
|
97
104
|
{ command: 'skills', description: '已安装的技能' },
|
|
98
105
|
{ command: 'soul', description: '代理人格设定' },
|
|
99
106
|
{ command: 'plugins', description: '列表与管理:add/remove/disable/enable' },
|
|
100
|
-
{ command: 'app', description: '
|
|
107
|
+
{ command: 'app', description: 'DSH 桌面应用(不是桥接)' },
|
|
101
108
|
{ command: 'restart', description: '重启桥接:/restart confirm' },
|
|
102
109
|
{ command: 'doctor', description: '诊断:桥接、网络、磁盘、目录、会话' },
|
|
103
110
|
{ command: 'logs', description: '桥接日志:/logs 50 或 /logs TG_NET' },
|
|
104
111
|
{ command: 'help', description: '全部命令与提示' },
|
|
105
112
|
{ command: 'lang', description: '界面语言:en、ru、zh' },
|
|
113
|
+
{ command: 'reasoning', description: '工作记录:/reasoning on|off' },
|
|
114
|
+
{ command: 'profile', description: '话题配置档:/profile <名称>,/profile new' },
|
|
115
|
+
{ command: 'thoughts', description: '上一轮的推理(稍后自动消失)' },
|
|
116
|
+
{ command: 'version', description: '桥接版本与 npm 上的最新版本' },
|
|
117
|
+
{ command: 'update', description: '从 npm 更新桥接:/update confirm' },
|
|
106
118
|
];
|
|
107
119
|
|
|
108
120
|
async function api(method, body) {
|