dsh-tg-bridge 1.33.2 → 1.34.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 +11 -8
- package/callbacks.mjs +5 -5
- package/control/cmd-bridge.mjs +23 -15
- package/control/cmd-model.mjs +1 -0
- package/control/cmd-skills.mjs +12 -2
- package/control/model-card.mjs +7 -1
- package/fallback.mjs +13 -2
- package/handle-message.mjs +6 -6
- package/i18n/en/core.mjs +5 -2
- package/i18n/en/ctrl.mjs +2 -0
- package/i18n/ru/core.mjs +5 -2
- package/i18n/ru/ctrl.mjs +2 -0
- package/i18n/zh/core.mjs +5 -2
- package/i18n/zh/ctrl.mjs +2 -0
- package/media.mjs +161 -22
- package/package.json +1 -1
- package/settings-card.mjs +13 -0
- package/thoughts.mjs +6 -1
- package/turn-events.mjs +20 -0
package/README.md
CHANGED
|
@@ -30,9 +30,10 @@ that answers, one step at a time.
|
|
|
30
30
|
[model,model]` writes the provider without an AI turn, and the key itself is
|
|
31
31
|
never typed — only the name of the variable that holds it. The new models appear
|
|
32
32
|
on `/model` as routes.
|
|
33
|
-
- **Input: text, voice, photos.**
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
- **Input: text, voice, photos.** Any speech engine plugs in — a local script, any
|
|
34
|
+
command-line tool, or an OpenAI-compatible API (see [`docs/VOICE.md`](docs/VOICE.md))
|
|
35
|
+
— and the transcript is shown before the answer. A photo is read by the turn's own
|
|
36
|
+
model through `read_image`, text and UI included; no second model is needed.
|
|
36
37
|
- **Goal and checklist per topic.** `/goal`, `/tasks`; both survive restarts and
|
|
37
38
|
are prepended to every turn.
|
|
38
39
|
- **Two scopes for every setting.** `/reasoning <mode> all` moves the default,
|
|
@@ -423,16 +424,18 @@ What each kind of attachment becomes inside a running turn:
|
|
|
423
424
|
|
|
424
425
|
| Sent | Inside the turn | Needs |
|
|
425
426
|
|---|---|---|
|
|
426
|
-
| voice note, audio file, audio sent as a document | transcript, echoed as `🎤 …` before the steer | `
|
|
427
|
+
| voice note, audio file, audio sent as a document | transcript, echoed as `🎤 …` before the steer | any engine you point `voice` at: `script`, `command` or an OpenAI-compatible `openai` endpoint; **off by default** |
|
|
427
428
|
| small text file (`.md`, `.json`, `.csv`, `.py`, `.log`, … up to 60 KB) | the content itself between `<file>` markers — no tool call needed | nothing |
|
|
428
429
|
| PDF, archive, binary, anything bigger | its local path under `~/.dsh/tg-bridge/inbox/` | nothing; the agent opens it with its own tools |
|
|
429
430
|
| video, video note, animation | its path; the agent can pull frames or sound out with ffmpeg | ffmpeg, only if frames or audio are needed |
|
|
430
431
|
| photo | its path plus one honest line; the turn reads it with `read_image`, and says so in one line if it cannot | a model that accepts images |
|
|
431
432
|
|
|
432
|
-
Voice is the one row with a hidden prerequisite
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
`
|
|
433
|
+
Voice is the one row with a hidden prerequisite: something has to turn audio into
|
|
434
|
+
text. Faster-whisper is what `init --voice` writes, but it is not the only answer —
|
|
435
|
+
`voice.provider` also takes `command` (whisper.cpp, Vosk, a wrapper of your own) or
|
|
436
|
+
`openai` (OpenAI, Groq, a local server; anything that speaks
|
|
437
|
+
`/audio/transcriptions`). With no backend configured, a voice note is not swallowed:
|
|
438
|
+
the bridge says what is missing and points at [`docs/VOICE.md`](docs/VOICE.md).
|
|
436
439
|
|
|
437
440
|
A caption does not turn the attachment into a text-only message: it is folded into the same
|
|
438
441
|
hand-over, so "why did this fail" plus a `.log` file arrives as one steer.
|
package/callbacks.mjs
CHANGED
|
@@ -122,7 +122,7 @@ export async function handleCallback(query) {
|
|
|
122
122
|
|
|
123
123
|
// A search result's plus button. The name came from the registry and the
|
|
124
124
|
// command is the one the hint under the list names, so a tap installs exactly
|
|
125
|
-
// what was read
|
|
125
|
+
// what was read — no hidden second path into pnpm.
|
|
126
126
|
if (data.startsWith('pl:i:')) {
|
|
127
127
|
const wanted = data.slice(5);
|
|
128
128
|
if (!/^(@[a-z0-9._-]+\/)?[a-z0-9._-]+$/i.test(wanted)) {
|
|
@@ -138,7 +138,7 @@ export async function handleCallback(query) {
|
|
|
138
138
|
|
|
139
139
|
// The up arrow on the update card. Same shape as the plus of a search result:
|
|
140
140
|
// the name was printed by the command that read the registry, and the tap runs
|
|
141
|
-
// `/plugin update <name>`
|
|
141
|
+
// `/plugin update <name>` — nothing else.
|
|
142
142
|
if (data.startsWith('pl:u:')) {
|
|
143
143
|
const wanted = data.slice(5);
|
|
144
144
|
if (!/^(@[a-z0-9._-]+\/)?[a-z0-9._-]+$/i.test(wanted)) {
|
|
@@ -155,7 +155,7 @@ export async function handleCallback(query) {
|
|
|
155
155
|
if (data.startsWith('fk:')) {
|
|
156
156
|
// A branch button from /branches. It does what `/resume <id>` does, so the
|
|
157
157
|
// topic moves onto that branch and the answer comes from the command
|
|
158
|
-
// itself
|
|
158
|
+
// itself — one implementation, one sentence.
|
|
159
159
|
const wanted = data.slice(3);
|
|
160
160
|
if (!/^session-[0-9a-f-]{36}$/.test(wanted)) {
|
|
161
161
|
await answer(t(lang, 'bridge.cb.unknown'));
|
|
@@ -184,7 +184,7 @@ export async function handleCallback(query) {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
// A button on the failover card. Every press becomes the verb of `/fallback`,
|
|
187
|
-
// so a tap and a typed line land in the same code
|
|
187
|
+
// so a tap and a typed line land in the same code — and the command redraws the
|
|
188
188
|
// card, which is why the old keyboard is trimmed only when the press leaves it.
|
|
189
189
|
if (isFallbackPress(data)) {
|
|
190
190
|
const target = pressTarget(data);
|
|
@@ -240,7 +240,7 @@ export async function handleCallback(query) {
|
|
|
240
240
|
const name = target.kind === 'command' ? target.name : '';
|
|
241
241
|
await clearKeyboard();
|
|
242
242
|
// `/new` and `/stop` change something when typed alone, and a stray tap on
|
|
243
|
-
// them is a command nobody asked for
|
|
243
|
+
// them is a command nobody asked for — so they open their explanation.
|
|
244
244
|
const typed = runsUnasked(name) && CONTROL_COMMANDS.includes(name)
|
|
245
245
|
? commandForName(name, { t: (k, v) => t(lang, k, v) })
|
|
246
246
|
: `/help ${name}`;
|
package/control/cmd-bridge.mjs
CHANGED
|
@@ -149,22 +149,30 @@ export async function handleBridgeCommands(ctx) {
|
|
|
149
149
|
return true;
|
|
150
150
|
}
|
|
151
151
|
say(t(lang, 'ctrl.app.restarting', { pids: before.join(', '), exe: EXE }));
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
spawn(EXE, [], { detached: true, stdio: 'ignore', windowsHide: false }).unref();
|
|
163
|
-
const up = await waitForStart(15000);
|
|
164
|
-
say(up.length
|
|
165
|
-
? t(lang, 'ctrl.app.restarted', { pids: up.join(', ') })
|
|
166
|
-
: t(lang, 'ctrl.app.notUp'));
|
|
152
|
+
// Kill the processes that were just named, one by one. An image-name kill
|
|
153
|
+
// takes down every program with that name — a second DSH opened for another
|
|
154
|
+
// profile, or an instance started after this list was read — and the message
|
|
155
|
+
// above promised the pids it lists, not every window on the machine.
|
|
156
|
+
const kill = (pid) => new Promise((resolve) => {
|
|
157
|
+
spawn('taskkill', ['/PID', String(pid), '/T', '/F'], { windowsHide: true, detached: true })
|
|
158
|
+
.on('close', resolve)
|
|
159
|
+
.on('error', resolve);
|
|
167
160
|
});
|
|
161
|
+
await Promise.all(before.map(kill));
|
|
162
|
+
const gone = await waitForExit(before, 12000);
|
|
163
|
+
if (!gone) {
|
|
164
|
+
say(t(lang, 'ctrl.app.stuck'));
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
if (!existsSync(EXE)) {
|
|
168
|
+
say(t(lang, 'ctrl.app.noExe', { exe: EXE }));
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
spawn(EXE, [], { detached: true, stdio: 'ignore', windowsHide: false }).unref();
|
|
172
|
+
const up = await waitForStart(15000);
|
|
173
|
+
say(up.length
|
|
174
|
+
? t(lang, 'ctrl.app.restarted', { pids: up.join(', ') })
|
|
175
|
+
: t(lang, 'ctrl.app.notUp'));
|
|
168
176
|
return true;
|
|
169
177
|
}
|
|
170
178
|
case '/stop': {
|
package/control/cmd-model.mjs
CHANGED
|
@@ -30,6 +30,7 @@ export async function handleModelCommand(ctx) {
|
|
|
30
30
|
current: routes.length ? { provider: topic.provider, model: topic.model } : null,
|
|
31
31
|
topic: topic.source === 'topic',
|
|
32
32
|
fallback: topic.source === 'topic' ? modelOf(activeProfile) : null,
|
|
33
|
+
answered: state.answered?.[key] || null,
|
|
33
34
|
t: (k, v) => t(lang, k, v),
|
|
34
35
|
});
|
|
35
36
|
say(card.text, { keyboard: card.keyboard });
|
package/control/cmd-skills.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { execFileSync, spawn, spawnSync } from 'node:child_process';
|
|
6
6
|
import { cpSync, existsSync, copyFileSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import { homedir, tmpdir } from 'node:os';
|
|
8
|
-
import { join,
|
|
8
|
+
import { basename, isAbsolute, join, relative } from 'node:path';
|
|
9
9
|
import { fileURLToPath } from 'node:url';
|
|
10
10
|
import { t, LANGS, normalizeLang } from '../i18n.mjs';
|
|
11
11
|
import { addTask, clearGoal, doneTask, editTask, finishGoal, goalOf, progressOf, reopenGoal, removeTask, setGoal } from '../goals.mjs';
|
|
@@ -46,7 +46,17 @@ export async function handleSkillCommands(ctx) {
|
|
|
46
46
|
const rows = skillsOf();
|
|
47
47
|
const want = (arg || '').trim();
|
|
48
48
|
if (want) {
|
|
49
|
-
|
|
49
|
+
// A skill is one directory under `skills/`, and the name here is whatever
|
|
50
|
+
// was typed: `join` walks out of the root for `../..`, so the resolved
|
|
51
|
+
// path is checked to still be inside before anything is read. The old
|
|
52
|
+
// code could be pointed at any `SKILL.md` on the disk.
|
|
53
|
+
const root = join(DSH_HOME, 'skills');
|
|
54
|
+
const dir = join(root, want);
|
|
55
|
+
const inside = relative(root, dir);
|
|
56
|
+
if (!inside || inside.startsWith('..') || isAbsolute(inside)) {
|
|
57
|
+
say(t(lang, 'ctrl.skills.none', { name: want }));
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
50
60
|
const body = read(join(dir, 'SKILL.md'));
|
|
51
61
|
say(body
|
|
52
62
|
? t(lang, 'ctrl.skills.body', { name: want, body: body.slice(0, 3000) })
|
package/control/model-card.mjs
CHANGED
|
@@ -68,7 +68,7 @@ export function modelPress(data) {
|
|
|
68
68
|
* provider prefix each is a wall, and a group heading stays readable when the
|
|
69
69
|
* models have long names.
|
|
70
70
|
*/
|
|
71
|
-
export function modelCard({ profile, routes, current = null, topic = false, fallback = null, t, limit = 60 }) {
|
|
71
|
+
export function modelCard({ profile, routes, current = null, topic = false, fallback = null, answered = null, t, limit = 60 }) {
|
|
72
72
|
const now = current || (routes.find((route) => route.current) || null);
|
|
73
73
|
const isNow = (route) => Boolean(now && route.provider === now.provider && route.model === now.model);
|
|
74
74
|
const known = routes.filter((route) => routeData(route.provider, route.model));
|
|
@@ -117,6 +117,12 @@ export function modelCard({ profile, routes, current = null, topic = false, fall
|
|
|
117
117
|
lines.push(t('ctrl.model.pickNowDefault', { route: `${fallback.provider}/${fallback.model}` }));
|
|
118
118
|
}
|
|
119
119
|
} else lines.push(t('ctrl.model.pickUnknown', { profile }));
|
|
120
|
+
// The route above is the one this topic is set to. After a fallback the turn
|
|
121
|
+
// ran somewhere else, and a card that only names the setting reads as "this is
|
|
122
|
+
// who answers" when it is not.
|
|
123
|
+
if (answered?.model) {
|
|
124
|
+
lines.push(t(answered.switched ? 'ctrl.model.answeredSwitched' : 'ctrl.model.answered', { model: answered.model }));
|
|
125
|
+
}
|
|
120
126
|
lines.push('');
|
|
121
127
|
// Three different silences, and they are not the same fact: a profile with no
|
|
122
128
|
// models at all, a profile whose every route is too long to be a button, and
|
package/fallback.mjs
CHANGED
|
@@ -237,7 +237,6 @@ export async function runFallbackChain({
|
|
|
237
237
|
tried.push(`${labelOf(entry)}: ${String(result.error).slice(0, 120)}`);
|
|
238
238
|
log(`fallback to ${labelOf(entry)} for ${where} family=${family} after: ${String(result.error).slice(0, 120)}`);
|
|
239
239
|
if (family === 'refused') refusals += 1;
|
|
240
|
-
telemetry.model = labelOf(entry);
|
|
241
240
|
// The person sees every switch, not only the final give-up: a chain of five
|
|
242
241
|
// companies that silently ends on the fifth reads like a hang.
|
|
243
242
|
await send(chatId, t(lang, 'bridge.fallback.switched', {
|
|
@@ -246,7 +245,13 @@ export async function runFallbackChain({
|
|
|
246
245
|
free: entry.free ? ' (free)' : '',
|
|
247
246
|
}), threadId);
|
|
248
247
|
result = await run(ensureProfile(entry.patch));
|
|
249
|
-
|
|
248
|
+
// Named only once it answers. Recording the attempt instead would make
|
|
249
|
+
// `/model` and the settings card claim a route that produced nothing.
|
|
250
|
+
if (!result.error) {
|
|
251
|
+
telemetry.model = labelOf(entry);
|
|
252
|
+
telemetry.switched = true;
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
250
255
|
}
|
|
251
256
|
|
|
252
257
|
// Every model refused. Before saying "all models are unavailable", ask each
|
|
@@ -272,6 +277,12 @@ export async function runFallbackChain({
|
|
|
272
277
|
const entry = entries.find((item) => item.model === live.model
|
|
273
278
|
&& (!live.provider || item.provider === live.provider));
|
|
274
279
|
result = await run(entry ? ensureProfile(entry.patch) : turnProfile);
|
|
280
|
+
// A retry after the probe counts as a switch too: the route that answered
|
|
281
|
+
// is not the one the topic names, which is the whole point of the line.
|
|
282
|
+
if (!result.error) {
|
|
283
|
+
telemetry.model = labelOf(live);
|
|
284
|
+
telemetry.switched = true;
|
|
285
|
+
}
|
|
275
286
|
} else {
|
|
276
287
|
// Nothing answers, or the request itself is what is refused: the verdict
|
|
277
288
|
// is the only useful part of the failure.
|
package/handle-message.mjs
CHANGED
|
@@ -25,7 +25,7 @@ import { settingsChipOf, turnPlan } from './profile-view.mjs';
|
|
|
25
25
|
import { startProgress } from './progress.mjs';
|
|
26
26
|
import { reportRefusals } from './sandbox-note.mjs';
|
|
27
27
|
import { noteTurn } from './stability.mjs';
|
|
28
|
-
import { makeTurnEvents, newTelemetry } from './turn-events.mjs';
|
|
28
|
+
import { makeTurnEvents, newTelemetry, noteAnswered } from './turn-events.mjs';
|
|
29
29
|
import { lastPrompt, maxParallel, queues } from './queue.mjs';
|
|
30
30
|
import { token } from './secrets.mjs';
|
|
31
31
|
import { config, done, log, saveConfig, saveState, state } from './state.mjs';
|
|
@@ -462,11 +462,8 @@ ${t(lang, 'help.body')}`,
|
|
|
462
462
|
return;
|
|
463
463
|
}
|
|
464
464
|
if (result.error) {
|
|
465
|
-
// The card
|
|
466
|
-
//
|
|
467
|
-
// code fault means the version on disk cannot be trusted, and does the
|
|
468
|
-
// rollback itself: a turn that throws is the only evidence a static check
|
|
469
|
-
// cannot produce.
|
|
465
|
+
// The card carries the failure; the log gets the detail. `noteTurn` decides
|
|
466
|
+
// whether a code fault means the version on disk cannot be trusted.
|
|
470
467
|
log(`turn failed ${where} ${seconds}s ${summary} :: ${result.error.slice(0, 400)}`);
|
|
471
468
|
await noteTurn(state, {
|
|
472
469
|
key, error: result.error, model: telemetry.model, tools: telemetry.toolNames, cwd, seconds,
|
|
@@ -476,6 +473,9 @@ ${t(lang, 'help.body')}`,
|
|
|
476
473
|
return;
|
|
477
474
|
}
|
|
478
475
|
log(`turn ok ${where} ${seconds}s session=${result.sessionId} ${summary}`);
|
|
476
|
+
// Who answered, for `/model` and the settings card: the card configures the
|
|
477
|
+
// topic's route, and after a fallback that route is not the one that replied.
|
|
478
|
+
noteAnswered(state, key, telemetry);
|
|
479
479
|
// An answered turn proves this release works, and makes it the version a later
|
|
480
480
|
// rollback returns to.
|
|
481
481
|
await noteTurn(state, { saveState });
|
package/i18n/en/core.mjs
CHANGED
|
@@ -75,7 +75,9 @@ export default {
|
|
|
75
75
|
'settings.reply.setBound': 'This topic uses set {name}: model, effort, permissions and preset come from it.',
|
|
76
76
|
'settings.card.changed': '✓ {label}: {value}',
|
|
77
77
|
'settings.card.stale': 'That button is from an older version of the card. Open /settings again.',
|
|
78
|
-
'settings.card.same': 'Already set',
|
|
78
|
+
'settings.card.same': 'Already set',
|
|
79
|
+
'model.answered': 'Last answer came from: {model}',
|
|
80
|
+
'model.answeredSwitched': 'Last answer came from {model} — the route of this topic did not answer',
|
|
79
81
|
'btn.stop': 'Stop',
|
|
80
82
|
'btn.logs': 'Logs',
|
|
81
83
|
'btn.retry': 'Retry',
|
|
@@ -199,6 +201,7 @@ export default {
|
|
|
199
201
|
'menu.lang': 'Interface language: en, ru, zh',
|
|
200
202
|
'msg.voiceDownloadFailed': 'Could not download the voice message: {err}',
|
|
201
203
|
'msg.voiceNotRecognized': 'Could not make out the voice message{detail}',
|
|
204
|
+
'msg.voiceOff': '🎤 Voice transcription is not set up here. `voice` takes any engine: a local script (`voice.python` + `voice.script`), any CLI (`voice.command` + `voice.args`), or an OpenAI-compatible API (`voice.baseUrl` + `voice.model` + a key). Ready-made blocks are in docs/VOICE.md.',
|
|
202
205
|
'prompt.photo': 'Look at the image at {path} and describe it in detail: text (verbatim, keeping its language), interface elements, objects.',
|
|
203
206
|
'prompt.file': 'The user sent a file: {path} ({type}, {size} bytes).',
|
|
204
207
|
'prompt.voice': '🎤 This is a transcript of a voice message, produced by speech recognition. Names, Latin words, file names and rare terms may be misheard. If a word makes no sense, ask what was meant instead of guessing — the text below is what was heard, not what was said.\n\n{text}',
|
|
@@ -257,7 +260,7 @@ export default {
|
|
|
257
260
|
'bridge.cb.allowed': 'Allowed',
|
|
258
261
|
'bridge.cb.denied': 'Denied',
|
|
259
262
|
'bridge.cb.unknown': 'Unknown button',
|
|
260
|
-
'bridge.cb.slow': 'Still working — no answer in {sec}s',
|
|
263
|
+
'bridge.cb.slow': 'Still working — no answer in {sec}s',
|
|
261
264
|
'bridge.cb.failed': 'The button failed — /logs errors has the reason',
|
|
262
265
|
'bridge.cb.slowLine':
|
|
263
266
|
'⚠️ That press answered nothing in {sec}s. It is still running — if it never finishes, /logs errors has the reason.',
|
package/i18n/en/ctrl.mjs
CHANGED
|
@@ -195,6 +195,8 @@ export default {
|
|
|
195
195
|
'ctrl.model.usage': 'Usage: /model <id> [both] (/model — list)',
|
|
196
196
|
'ctrl.model.failed': 'Could not switch {name} to "{model}": the profile has no agent-default-model line. /model — list.',
|
|
197
197
|
'ctrl.model.switched': 'Model {name} → {model}{desktop}. Applies from the next turn.',
|
|
198
|
+
'ctrl.model.answered': 'Last answer came from: {model}',
|
|
199
|
+
'ctrl.model.answeredSwitched': 'Last answer came from {model} — the route of this topic did not answer',
|
|
198
200
|
'ctrl.model.withDesktop': ', desktop → {model}',
|
|
199
201
|
'ctrl.sessions.empty': 'No sessions found.',
|
|
200
202
|
'ctrl.sessions.title': '🗂 Recent sessions:',
|
package/i18n/ru/core.mjs
CHANGED
|
@@ -75,7 +75,9 @@ export default {
|
|
|
75
75
|
'settings.reply.setBound': 'Тема использует набор {name}: модель, усилие, права и пресет берутся из него.',
|
|
76
76
|
'settings.card.changed': '✓ {label}: {value}',
|
|
77
77
|
'settings.card.stale': 'Эта кнопка из старой версии карточки. Открой /settings заново.',
|
|
78
|
-
'settings.card.same': 'Уже так и стоит',
|
|
78
|
+
'settings.card.same': 'Уже так и стоит',
|
|
79
|
+
'model.answered': 'Последним отвечал: {model}',
|
|
80
|
+
'model.answeredSwitched': 'Последним отвечал {model} — свой маршрут темы не ответил',
|
|
79
81
|
'btn.stop': 'Стоп',
|
|
80
82
|
'btn.logs': 'Логи',
|
|
81
83
|
'btn.retry': 'Повторить',
|
|
@@ -199,6 +201,7 @@ export default {
|
|
|
199
201
|
'menu.lang': 'Язык интерфейса: en, ru, zh',
|
|
200
202
|
'msg.voiceDownloadFailed': 'Не смог скачать голосовое: {err}',
|
|
201
203
|
'msg.voiceNotRecognized': 'Не распознал голосовое{detail}',
|
|
204
|
+
'msg.voiceOff': '🎤 Расшифровка голоса здесь не настроена. В `voice` подойдёт любой движок: локальный скрипт (`voice.python` + `voice.script`), любая CLI (`voice.command` + `voice.args`) или OpenAI-совместимый API (`voice.baseUrl` + `voice.model` + ключ). Готовые блоки — в docs/VOICE.md.',
|
|
202
205
|
'prompt.photo': 'Посмотри изображение по пути {path} и подробно опиши, что на нём: текст (дословно, с сохранением языка), элементы интерфейса, объекты.',
|
|
203
206
|
'prompt.file': 'Пользователь прислал файл: {path} ({type}, {size} байт).',
|
|
204
207
|
'prompt.voice': '🎤 Это расшифровка голосового сообщения, сделанная распознаванием речи. Имена, латиница, имена файлов и редкие слова могут быть перевраны. Если слово выглядит бессмысленно, спроси, что имелось в виду, вместо того чтобы додумывать: ниже — то, что услышано, а не то, что сказано.\n\n{text}',
|
|
@@ -257,7 +260,7 @@ export default {
|
|
|
257
260
|
'bridge.cb.allowed': 'Разрешено',
|
|
258
261
|
'bridge.cb.denied': 'Запрещено',
|
|
259
262
|
'bridge.cb.unknown': 'Неизвестная кнопка',
|
|
260
|
-
'bridge.cb.slow': 'Ещё работаю — ответа нет {sec} с',
|
|
263
|
+
'bridge.cb.slow': 'Ещё работаю — ответа нет {sec} с',
|
|
261
264
|
'bridge.cb.failed': 'Кнопка сорвалась — причина в /logs errors',
|
|
262
265
|
'bridge.cb.slowLine':
|
|
263
266
|
'⚠️ Нажатие ничего не ответило за {sec} с. Оно всё ещё выполняется — если так и не закончится, причина будет в /logs errors.',
|
package/i18n/ru/ctrl.mjs
CHANGED
|
@@ -195,6 +195,8 @@ export default {
|
|
|
195
195
|
'ctrl.model.usage': 'Использование: /model <id> [both] (/model — список)',
|
|
196
196
|
'ctrl.model.failed': 'Не смог переключить {name} на «{model}»: в профиле нет строки agent-default-model. /model — список.',
|
|
197
197
|
'ctrl.model.switched': 'Модель {name} → {model}{desktop}. Действует со следующего хода.',
|
|
198
|
+
'ctrl.model.answered': 'Последним отвечал: {model}',
|
|
199
|
+
'ctrl.model.answeredSwitched': 'Последним отвечал {model} — свой маршрут темы не ответил',
|
|
198
200
|
'ctrl.model.withDesktop': ', desktop → {model}',
|
|
199
201
|
'ctrl.sessions.empty': 'Сессий не нашёл.',
|
|
200
202
|
'ctrl.sessions.title': '🗂 Последние сессии:',
|
package/i18n/zh/core.mjs
CHANGED
|
@@ -75,7 +75,9 @@ export default {
|
|
|
75
75
|
'settings.reply.setBound': '本话题使用组合 {name}:模型、力度、权限、预设都来自它。',
|
|
76
76
|
'settings.card.changed': '✓ {label}:{value}',
|
|
77
77
|
'settings.card.stale': '这个按钮来自旧版卡片。请重新打开 /settings。',
|
|
78
|
-
'settings.card.same': '已经是这样',
|
|
78
|
+
'settings.card.same': '已经是这样',
|
|
79
|
+
'model.answered': '上次回答来自:{model}',
|
|
80
|
+
'model.answeredSwitched': '上次回答来自 {model} — 本主题自己的路由没有回应',
|
|
79
81
|
'btn.stop': '停止',
|
|
80
82
|
'btn.logs': '日志',
|
|
81
83
|
'btn.retry': '重试',
|
|
@@ -199,6 +201,7 @@ export default {
|
|
|
199
201
|
'menu.lang': '界面语言:en、ru、zh',
|
|
200
202
|
'msg.voiceDownloadFailed': '语音下载失败:{err}',
|
|
201
203
|
'msg.voiceNotRecognized': '没能识别这条语音{detail}',
|
|
204
|
+
'msg.voiceOff': '🎤 这里还没有配置语音转写。`voice` 可以接任意引擎:本地脚本(`voice.python` + `voice.script`)、任意命令行(`voice.command` + `voice.args`),或 OpenAI 兼容接口(`voice.baseUrl` + `voice.model` + 密钥)。现成配置见 docs/VOICE.md。',
|
|
202
205
|
'prompt.photo': '查看路径 {path} 的图片并详细描述:文字(逐字,保留原语言)、界面元素、物体。',
|
|
203
206
|
'prompt.file': '用户发来文件:{path}({type},{size} 字节)。',
|
|
204
207
|
'prompt.voice': '🎤 这是语音消息的转写文本,由语音识别生成。人名、拉丁字母、文件名和生僻词可能听错。如果某个词看起来没有意义,请询问本意,不要自行猜测:下面是被听到的内容,不一定是原话。\n\n{text}',
|
|
@@ -257,7 +260,7 @@ export default {
|
|
|
257
260
|
'bridge.cb.allowed': '已允许',
|
|
258
261
|
'bridge.cb.denied': '已拒绝',
|
|
259
262
|
'bridge.cb.unknown': '未知按钮',
|
|
260
|
-
'bridge.cb.slow': '仍在处理 — {sec} 秒内没有回应',
|
|
263
|
+
'bridge.cb.slow': '仍在处理 — {sec} 秒内没有回应',
|
|
261
264
|
'bridge.cb.failed': '按钮执行失败 — 原因在 /logs errors 里',
|
|
262
265
|
'bridge.cb.slowLine':
|
|
263
266
|
'⚠️ 这次点击 {sec} 秒内没有任何回应。它仍在执行 — 若一直不结束,原因会在 /logs errors 里。',
|
package/i18n/zh/ctrl.mjs
CHANGED
|
@@ -195,6 +195,8 @@ export default {
|
|
|
195
195
|
'ctrl.model.usage': '用法:/model <id> [both] (/model 查看列表)',
|
|
196
196
|
'ctrl.model.failed': '无法把 {name} 切换到「{model}」:配置档中没有 agent-default-model 行。/model 查看列表。',
|
|
197
197
|
'ctrl.model.switched': '模型 {name} → {model}{desktop}。下一轮生效。',
|
|
198
|
+
'ctrl.model.answered': '上次回答来自:{model}',
|
|
199
|
+
'ctrl.model.answeredSwitched': '上次回答来自 {model} — 本主题自己的路由没有回应',
|
|
198
200
|
'ctrl.model.withDesktop': ',desktop → {model}',
|
|
199
201
|
'ctrl.sessions.empty': '没有找到会话。',
|
|
200
202
|
'ctrl.sessions.title': '🗂 最近的会话:',
|
package/media.mjs
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
// and the hand-over are one job with three failure modes of its own.
|
|
4
4
|
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
|
-
import { existsSync, mkdirSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
7
|
-
import { join } from 'node:path';
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
7
|
+
import { basename, isAbsolute, join } from 'node:path';
|
|
8
|
+
import { tmpdir } from 'node:os';
|
|
8
9
|
import { DIR } from './paths.mjs';
|
|
9
10
|
import { config, log } from './state.mjs';
|
|
10
11
|
import { token } from './secrets.mjs';
|
|
@@ -13,17 +14,123 @@ import { downloadFile, send, tg } from './telegram.mjs';
|
|
|
13
14
|
import { inlineText } from './media-text.mjs';
|
|
14
15
|
import { ensureProfile } from './profiles.mjs';
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
+
* Which backend reads the audio: `voice.provider` when the config names one, and
|
|
18
|
+
* otherwise the shape of the config itself, so an install that only has the old
|
|
19
|
+
* keys keeps working across an update. Three shapes, chosen by the person:
|
|
17
20
|
*
|
|
18
|
-
*
|
|
19
|
-
* -
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* - `script` — a local faster-whisper script (`voice.python` + `voice.script`);
|
|
22
|
+
* - `command` — any whisper.cpp-style CLI (`voice.command` + `voice.args`);
|
|
23
|
+
* - `openai` — any OpenAI-compatible `/audio/transcriptions` endpoint:
|
|
24
|
+
* OpenAI, Groq, DeepInfra, a local vLLM or `whisper.cpp` server, and whatever
|
|
25
|
+
* else speaks the same request. `voice.baseUrl` + `voice.model` + a key.
|
|
26
|
+
*
|
|
27
|
+
* The point of `openai` is that nobody is married to the model this repo happened
|
|
28
|
+
* to install: the endpoint and the model name are fields, not code.
|
|
23
29
|
*/
|
|
24
|
-
export function
|
|
25
|
-
const
|
|
30
|
+
export function voiceProvider(voice = {}) {
|
|
31
|
+
const named = String(voice.provider || '').toLowerCase();
|
|
32
|
+
if (named === 'script' || named === 'command' || named === 'openai') return named;
|
|
33
|
+
if (voice.python && voice.script) return 'script';
|
|
34
|
+
if (voice.baseUrl && voice.model) return 'openai';
|
|
35
|
+
if (voice.command) return 'command';
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Whether this config can read audio at all — used before offering to. */
|
|
40
|
+
export function voiceConfigured(voice = {}) {
|
|
41
|
+
const provider = voiceProvider(voice);
|
|
42
|
+
if (provider === 'openai') {
|
|
43
|
+
// The name of the variable is not the key: a config that only sets
|
|
44
|
+
// `apiKeyEnv` is still missing the value, and pretending otherwise turns
|
|
45
|
+
// "not set up" into a failed request.
|
|
46
|
+
return Boolean(voice.model && (voice.apiKey || (voice.apiKeyEnv && process.env[voice.apiKeyEnv])));
|
|
47
|
+
}
|
|
48
|
+
if (provider === 'script') return Boolean(voice.python && voice.script);
|
|
49
|
+
if (provider === 'command') return Boolean(voice.command);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function transcribe(file, voice = {}) {
|
|
54
|
+
const provider = voiceProvider(voice);
|
|
55
|
+
if (provider === 'openai') return transcribeHttp(file, voice);
|
|
56
|
+
if (provider === 'script' || provider === 'command') return transcribeLocal(file, voice, provider === 'script');
|
|
57
|
+
return Promise.resolve({ text: '', error: 'no speech backend: set voice.provider to script, command or openai' });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A hosted or self-hosted endpoint that answers the OpenAI transcription request.
|
|
62
|
+
* The body is assembled here instead of in a dependency: it is one multipart form.
|
|
63
|
+
*/
|
|
64
|
+
async function transcribeHttp(file, voice) {
|
|
65
|
+
const base = String(voice.baseUrl || 'https://api.openai.com/v1').replace(/\/+$/, '');
|
|
66
|
+
const key = voice.apiKey || process.env[voice.apiKeyEnv || ''] || '';
|
|
67
|
+
// The message goes into the chat, so it names the setting, never the value.
|
|
68
|
+
if (!key) return { text: '', error: `no key for ${base}: set voice.apiKey or voice.apiKeyEnv` };
|
|
69
|
+
let audio;
|
|
70
|
+
try {
|
|
71
|
+
audio = readFileSync(file);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
return { text: '', error: `cannot read the audio: ${error.code || error.message}` };
|
|
74
|
+
}
|
|
75
|
+
const form = new FormData();
|
|
76
|
+
form.set('file', new Blob([audio]), basename(file));
|
|
77
|
+
form.set('model', voice.model);
|
|
78
|
+
if (voice.language && voice.language !== 'auto') form.set('language', voice.language);
|
|
79
|
+
let res;
|
|
80
|
+
try {
|
|
81
|
+
res = await fetch(`${base}/audio/transcriptions`, {
|
|
82
|
+
method: 'POST',
|
|
83
|
+
headers: { authorization: `Bearer ${key}` },
|
|
84
|
+
body: form,
|
|
85
|
+
signal: AbortSignal.timeout(voice.timeoutMs || 120000),
|
|
86
|
+
});
|
|
87
|
+
} catch (error) {
|
|
88
|
+
log(`voice http: ${base} ${error.name || error.message}`);
|
|
89
|
+
return { text: '', error: error.name === 'TimeoutError' ? 'the speech endpoint timed out' : 'the speech endpoint did not answer' };
|
|
90
|
+
}
|
|
91
|
+
const raw = await res.text();
|
|
92
|
+
if (!res.ok) {
|
|
93
|
+
// Some providers put a readable reason in the body ("model not found", "bad
|
|
94
|
+
// key"); keep it short and log it without the key or the audio.
|
|
95
|
+
log(`voice http ${res.status} from ${base}: ${raw.slice(0, 200)}`);
|
|
96
|
+
return { text: '', error: `the speech endpoint answered ${res.status}` };
|
|
97
|
+
}
|
|
98
|
+
let text = '';
|
|
99
|
+
try {
|
|
100
|
+
text = String(JSON.parse(raw).text || '');
|
|
101
|
+
} catch {
|
|
102
|
+
// `response_format=text` and a few servers answer with the transcript itself.
|
|
103
|
+
text = raw;
|
|
104
|
+
}
|
|
105
|
+
return { text: text.trim(), error: '' };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The local shapes: spawn an interpreter with our script, or a whisper CLI. */
|
|
109
|
+
function transcribeLocal(file, voice, useScript) {
|
|
26
110
|
const command = useScript ? voice.python : voice.command;
|
|
111
|
+
// The interpreter and the script are named by absolute path or not at all. A
|
|
112
|
+
// bare `python` is looked up on PATH *and* in the working directory, so a file
|
|
113
|
+
// dropped next to the install could answer for the interpreter; the same field
|
|
114
|
+
// hand-edited in `config.json` would point transcription at any program. A
|
|
115
|
+
// whisper.cpp-style `command` stays exempt: `whisper-cli` on PATH is the normal
|
|
116
|
+
// way to install it, and it is not an interpreter that will run our script.
|
|
117
|
+
if (useScript && (!isAbsolute(command) || !isAbsolute(voice.script))) {
|
|
118
|
+
log(`voice: python=${command} script=${voice.script} — both must be absolute`);
|
|
119
|
+
return Promise.resolve({ text: '', error: 'voice.python and voice.script must be absolute paths' });
|
|
120
|
+
}
|
|
121
|
+
const cwd = voice.cwd || DIR;
|
|
122
|
+
// A cwd that does not exist is a typo, and a spawn error names the file rather
|
|
123
|
+
// than the setting that is actually wrong.
|
|
124
|
+
if (voice.cwd && !(existsSync(cwd) && statSync(cwd).isDirectory())) {
|
|
125
|
+
log(`voice: cwd=${cwd} is not a directory`);
|
|
126
|
+
return Promise.resolve({ text: '', error: 'voice.cwd is not a directory' });
|
|
127
|
+
}
|
|
128
|
+
// `{out}` is a temp path the engine may write to: whisper.cpp is not the only
|
|
129
|
+
// program people run — Vosk, WhisperX, GigaAM wrappers and plain ffmpeg chains
|
|
130
|
+
// all exist, and most of them either print the text or write it to a file given
|
|
131
|
+
// on the command line. Both shapes fit in a template, so the config stays data.
|
|
132
|
+
const out = join(tmpdir(), `dsh-voice-${Date.now()}-${process.pid}`);
|
|
133
|
+
const fill = (value) => String(value).replaceAll('{file}', file).replaceAll('{out}', out);
|
|
27
134
|
const args = useScript
|
|
28
135
|
? [
|
|
29
136
|
voice.script,
|
|
@@ -33,7 +140,7 @@ export function transcribe(file, voice) {
|
|
|
33
140
|
'--beam', String(voice.beam ?? 1),
|
|
34
141
|
'--threads', String(voice.threads ?? 0),
|
|
35
142
|
]
|
|
36
|
-
: (voice.args ?? []).map(
|
|
143
|
+
: (voice.args ?? []).map(fill);
|
|
37
144
|
if (!useScript && !(voice.args ?? []).some((arg) => String(arg).includes('{file}'))) args.push(file);
|
|
38
145
|
return new Promise((resolve) => {
|
|
39
146
|
const child = spawn(command, args, {
|
|
@@ -53,15 +160,38 @@ export function transcribe(file, voice) {
|
|
|
53
160
|
child.stderr.on('data', (buf) => { stderr += buf; });
|
|
54
161
|
child.on('error', (err) => resolve({ text: '', error: `${command}: ${err.message}` }));
|
|
55
162
|
child.on('close', (code) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
163
|
+
let text = '';
|
|
164
|
+
if (!useScript && voice.output === 'file') {
|
|
165
|
+
// The engine wrote the transcript where the template said; the file is
|
|
166
|
+
// removed with the temp path afterwards, so the person's inbox stays clean.
|
|
167
|
+
const target = fill(voice.outputFile || '{out}');
|
|
168
|
+
try {
|
|
169
|
+
text = readFileSync(target, 'utf8').trim();
|
|
170
|
+
} catch (error) {
|
|
171
|
+
resolve({ text: '', error: `${basename(command)} wrote no transcript to ${basename(target)}: ${error.code || error.message}` });
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
try { unlinkSync(target); } catch {}
|
|
175
|
+
} else if (!useScript && voice.output === 'json') {
|
|
176
|
+
// {"text": "…"} is the common shape; Vosk answers {"result": [{text}…]}.
|
|
177
|
+
try {
|
|
178
|
+
const data = JSON.parse(stdout);
|
|
179
|
+
text = String(data.text ?? (Array.isArray(data.result) ? data.result.map((r) => r.text || '').join(' ') : ''));
|
|
180
|
+
} catch {
|
|
181
|
+
text = '';
|
|
182
|
+
}
|
|
183
|
+
if (!text) text = stdout.trim();
|
|
184
|
+
} else {
|
|
185
|
+
// whisper.cpp writes timestamps and `[BLANK_AUDIO]` markers; keep only speech.
|
|
186
|
+
text = stdout
|
|
187
|
+
.split(/\r?\n/)
|
|
188
|
+
.map((line) => line.replace(/^\s*\[[\d:.,\s>-]+\]\s*/, '').replace(/\[BLANK_AUDIO\]/gi, '').trim())
|
|
189
|
+
.filter(Boolean)
|
|
190
|
+
.join(' ')
|
|
191
|
+
.replace(/\s+/g, ' ')
|
|
192
|
+
.trim();
|
|
193
|
+
}
|
|
194
|
+
resolve({ text: text.replace(/\s+/g, ' ').trim(), error: code === 0 ? '' : `${voice.command} exit ${code}: ${stderr.trim().slice(-300)}` });
|
|
65
195
|
});
|
|
66
196
|
});
|
|
67
197
|
}
|
|
@@ -166,19 +296,28 @@ export function voicePromptText(heard, lang) {
|
|
|
166
296
|
*/
|
|
167
297
|
export async function mediaPrompt(msgs, chatId, threadId, lang, opts = {}) {
|
|
168
298
|
const list = Array.isArray(msgs) ? msgs : [msgs];
|
|
169
|
-
|
|
170
|
-
|
|
299
|
+
// `enabled` is the master switch; `voiceConfigured` knows every backend shape,
|
|
300
|
+
// so a key-only (hosted) setup is not mistaken for a missing one.
|
|
301
|
+
const voiceOn = Boolean(config.voice?.enabled) && voiceConfigured(config.voice);
|
|
171
302
|
const parts = [];
|
|
172
303
|
let extraArgs = [];
|
|
173
304
|
/** Profile the turn must run on (only an opt-in photo overlay overrides it). */
|
|
174
305
|
let profile = '';
|
|
175
306
|
let caption = '';
|
|
176
307
|
let photo = false;
|
|
308
|
+
// A voice note with no backend used to be dropped without a word: the person
|
|
309
|
+
// saw the bot ignore them, and nothing said the engine was missing. Once per
|
|
310
|
+
// batch is enough — an album of clips must not repeat the same line.
|
|
311
|
+
let voiceTold = false;
|
|
177
312
|
for (const msg of list) {
|
|
178
313
|
if (!caption && (msg.caption || '').trim()) caption = msg.caption.trim();
|
|
179
314
|
if (msg.voice || msg.audio) {
|
|
180
315
|
if (!voiceOn) {
|
|
181
316
|
log('audio ignored: voice transcription is off or misconfigured');
|
|
317
|
+
if (!voiceTold) {
|
|
318
|
+
voiceTold = true;
|
|
319
|
+
await send(chatId, t(lang, 'msg.voiceOff'), threadId);
|
|
320
|
+
}
|
|
182
321
|
continue;
|
|
183
322
|
}
|
|
184
323
|
const heard = await readVoiceIntoText(msg, chatId, threadId, lang);
|
package/package.json
CHANGED
package/settings-card.mjs
CHANGED
|
@@ -166,6 +166,10 @@ export function settingsCurrent({ config = {}, state = {}, key = '' }) {
|
|
|
166
166
|
reasoningAll: reasoningMode(state, config, ''),
|
|
167
167
|
lang: state.lang?.[key] || 'auto',
|
|
168
168
|
pin: cardPin(state, config, key),
|
|
169
|
+
// Who answered the last turn that finished: the topic's route is what this
|
|
170
|
+
// card configures, but after a fallback the honest answer is the model that
|
|
171
|
+
// actually replied — and the card is where a person looks to check.
|
|
172
|
+
answered: state.answered?.[key] || null,
|
|
169
173
|
};
|
|
170
174
|
}
|
|
171
175
|
|
|
@@ -225,6 +229,15 @@ export function renderSettingsCard({ page = 'reply', t, current = {}, updateMode
|
|
|
225
229
|
profile: current.permissions.profile || '',
|
|
226
230
|
}));
|
|
227
231
|
}
|
|
232
|
+
// Who actually answered last, and whether that was the chain rather than this
|
|
233
|
+
// topic's own route. The card names the route it configures a few rows above,
|
|
234
|
+
// so without this line a topic running on a fallback looks like it is running
|
|
235
|
+
// on the route printed there.
|
|
236
|
+
if (page === 'agent' && current.answered?.model) {
|
|
237
|
+
lines.push(t(current.answered.switched ? 'model.answeredSwitched' : 'model.answered', {
|
|
238
|
+
model: current.answered.model,
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
228
241
|
if (page === 'reply' && bound) lines.push('', t('settings.reply.setBound', { name: bound.name || bound.id }));
|
|
229
242
|
lines.push('', t('settings.card.foot'));
|
|
230
243
|
|
package/thoughts.mjs
CHANGED
|
@@ -35,6 +35,11 @@ function frameStarts(buf) {
|
|
|
35
35
|
/** Path of a session file, or '' when the id is unknown. */
|
|
36
36
|
export function sessionFile(sessionsRoot, sessionId) {
|
|
37
37
|
if (!sessionId) return '';
|
|
38
|
+
// The id reaches this file from the state file and from `/sessions <id>`, so it
|
|
39
|
+
// is text somebody typed. `join` happily walks up from `..`, and the id alone
|
|
40
|
+
// decides which directory is read: one safe shape, checked here, closes that.
|
|
41
|
+
const id = String(sessionId);
|
|
42
|
+
if (!/^[A-Za-z0-9._-]{1,128}$/.test(id) || id === '.' || id === '..' || id.includes('..')) return '';
|
|
38
43
|
let dirs = [];
|
|
39
44
|
try {
|
|
40
45
|
dirs = readdirSync(sessionsRoot, { withFileTypes: true }).filter((e) => e.isDirectory());
|
|
@@ -42,7 +47,7 @@ export function sessionFile(sessionsRoot, sessionId) {
|
|
|
42
47
|
return '';
|
|
43
48
|
}
|
|
44
49
|
for (const dir of dirs) {
|
|
45
|
-
const direct = join(sessionsRoot, dir.name,
|
|
50
|
+
const direct = join(sessionsRoot, dir.name, id, 'session.v4.jsonl.zstd');
|
|
46
51
|
if (existsSync(direct)) return direct;
|
|
47
52
|
}
|
|
48
53
|
return '';
|
package/turn-events.mjs
CHANGED
|
@@ -30,6 +30,26 @@ export function newTelemetry(model = '') {
|
|
|
30
30
|
// state file and its model in a patch file, and a module that counts tool
|
|
31
31
|
// calls has no business reading either.
|
|
32
32
|
model,
|
|
33
|
+
// Set by the fallback chain when a route other than the topic's own answered.
|
|
34
|
+
// The model field alone cannot say that: it is also the configured model.
|
|
35
|
+
switched: false,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Remember who answered, per topic, for `/model` and the settings card.
|
|
41
|
+
*
|
|
42
|
+
* Both cards name the route the topic is *configured* with. After a fallback
|
|
43
|
+
* that is not the route that replied, and the difference is the one thing a
|
|
44
|
+
* person checking "why is this slow/vague" needs to see. Kept here because the
|
|
45
|
+
* telemetry is what knows, and the message handler is at its size ceiling.
|
|
46
|
+
*/
|
|
47
|
+
export function noteAnswered(state, key, telemetry = {}) {
|
|
48
|
+
state.answered = state.answered || {};
|
|
49
|
+
state.answered[key] = {
|
|
50
|
+
model: telemetry.model || '',
|
|
51
|
+
switched: Boolean(telemetry.switched),
|
|
52
|
+
at: Date.now(),
|
|
33
53
|
};
|
|
34
54
|
}
|
|
35
55
|
|