dsh-tg-bridge 1.38.2 → 1.38.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/chat/reply-guard.mjs +55 -55
- package/control/model-card.mjs +14 -6
- package/docs/CHANGELOG.md +22 -0
- package/package.json +1 -1
package/chat/reply-guard.mjs
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
// What the chat sends when the model hands back its own notes instead of a reply.
|
|
2
|
-
//
|
|
3
|
-
// The headless CLI's `final` text is the turn's last assistant text, and a turn
|
|
4
|
-
// that produced no answer reports the reasoning. Forwarding it reads as "the bot
|
|
5
|
-
// answers with its thinking", and suppressing it reads as "the turn died" — both
|
|
6
|
-
// were real, and both are the same defect seen from two sides. The guard here
|
|
7
|
-
// asks once more, in the same session, for a finished reply; only when that also
|
|
8
|
-
// comes back as notes does it send the honest sentence.
|
|
9
|
-
//
|
|
10
|
-
// Extracted from `handle-message.mjs`, which is at its size ceiling and whose
|
|
11
|
-
// subject is "one incoming message becomes one turn", not "what a reply is".
|
|
12
|
-
import { looksLikeReasoning, REPLY_NUDGE, stripThinkingBlocks } from './panel.mjs';
|
|
13
|
-
import { turnAttempt } from '../turn/turn.mjs';
|
|
14
|
-
|
|
15
|
-
/** Is this text the reasoning the panel already holds, markers included? */
|
|
16
|
-
export function isReasoningEcho(value, reasoning) {
|
|
17
|
-
return looksLikeReasoning(value, reasoning);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Produce the text the chat should send, asking the model once more if needed.
|
|
22
|
-
*
|
|
23
|
-
* @param {object} input
|
|
24
|
-
* @param {object} input.result the finished turn: `{ text, error }`, replaced in
|
|
25
|
-
* place when the second attempt produces a real answer
|
|
26
|
-
* @param {() => string} input.reasoning the reasoning this turn collected
|
|
27
|
-
* @param {string} input.key the topic key
|
|
28
|
-
* @param {object} input.turnOptions the options the first attempt ran with, so
|
|
29
|
-
* the second attempt cannot drift from it
|
|
30
|
-
* @param {string} input.sessionId the session the first attempt ran in
|
|
31
|
-
* @param {string} input.where the log label for this topic
|
|
32
|
-
* @param {(line: string) => void} input.log
|
|
33
|
-
* @param {Function} [input.retryTurn] builds the second attempt; defaults to the
|
|
34
|
-
* real one. Injectable because the guard's tests must not spawn a CLI.
|
|
35
|
-
* @returns {Promise<{ text: string, echoed: boolean }>} `echoed` means nothing
|
|
36
|
-
* the person should read was produced, and the caller sends its own sentence
|
|
37
|
-
*/
|
|
38
|
-
export async function replyText({ result, reasoning, key, turnOptions, sessionId, where, log, retryTurn = turnAttempt }) {
|
|
39
|
-
const echoed = (value) => isReasoningEcho(value, reasoning());
|
|
40
|
-
if (echoed(result.text)) {
|
|
41
|
-
log(`reasoning echo for ${where} (${String(result.text).length} chars) — asking once more`);
|
|
42
|
-
const retry = await retryTurn(REPLY_NUDGE, key, turnOptions)(sessionId);
|
|
43
|
-
if (!retry.error && !echoed(retry.text) && stripThinkingBlocks(retry.text)) {
|
|
44
|
-
Object.assign(result, retry);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (echoed(result.text)) {
|
|
48
|
-
log(`reasoning echo suppressed for ${where} (${String(result.text).length} chars)`);
|
|
49
|
-
return { text: '', echoed: true };
|
|
50
|
-
}
|
|
51
|
-
// The marker can survive inside an otherwise real reply; the chat never shows it.
|
|
52
|
-
return { text: stripThinkingBlocks(result.text), echoed: false };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export { REPLY_NUDGE };
|
|
1
|
+
// What the chat sends when the model hands back its own notes instead of a reply.
|
|
2
|
+
//
|
|
3
|
+
// The headless CLI's `final` text is the turn's last assistant text, and a turn
|
|
4
|
+
// that produced no answer reports the reasoning. Forwarding it reads as "the bot
|
|
5
|
+
// answers with its thinking", and suppressing it reads as "the turn died" — both
|
|
6
|
+
// were real, and both are the same defect seen from two sides. The guard here
|
|
7
|
+
// asks once more, in the same session, for a finished reply; only when that also
|
|
8
|
+
// comes back as notes does it send the honest sentence.
|
|
9
|
+
//
|
|
10
|
+
// Extracted from `handle-message.mjs`, which is at its size ceiling and whose
|
|
11
|
+
// subject is "one incoming message becomes one turn", not "what a reply is".
|
|
12
|
+
import { looksLikeReasoning, REPLY_NUDGE, stripThinkingBlocks } from './panel.mjs';
|
|
13
|
+
import { turnAttempt } from '../turn/turn.mjs';
|
|
14
|
+
|
|
15
|
+
/** Is this text the reasoning the panel already holds, markers included? */
|
|
16
|
+
export function isReasoningEcho(value, reasoning) {
|
|
17
|
+
return looksLikeReasoning(value, reasoning);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Produce the text the chat should send, asking the model once more if needed.
|
|
22
|
+
*
|
|
23
|
+
* @param {object} input
|
|
24
|
+
* @param {object} input.result the finished turn: `{ text, error }`, replaced in
|
|
25
|
+
* place when the second attempt produces a real answer
|
|
26
|
+
* @param {() => string} input.reasoning the reasoning this turn collected
|
|
27
|
+
* @param {string} input.key the topic key
|
|
28
|
+
* @param {object} input.turnOptions the options the first attempt ran with, so
|
|
29
|
+
* the second attempt cannot drift from it
|
|
30
|
+
* @param {string} input.sessionId the session the first attempt ran in
|
|
31
|
+
* @param {string} input.where the log label for this topic
|
|
32
|
+
* @param {(line: string) => void} input.log
|
|
33
|
+
* @param {Function} [input.retryTurn] builds the second attempt; defaults to the
|
|
34
|
+
* real one. Injectable because the guard's tests must not spawn a CLI.
|
|
35
|
+
* @returns {Promise<{ text: string, echoed: boolean }>} `echoed` means nothing
|
|
36
|
+
* the person should read was produced, and the caller sends its own sentence
|
|
37
|
+
*/
|
|
38
|
+
export async function replyText({ result, reasoning, key, turnOptions, sessionId, where, log, retryTurn = turnAttempt }) {
|
|
39
|
+
const echoed = (value) => isReasoningEcho(value, reasoning());
|
|
40
|
+
if (echoed(result.text)) {
|
|
41
|
+
log(`reasoning echo for ${where} (${String(result.text).length} chars) — asking once more`);
|
|
42
|
+
const retry = await retryTurn(REPLY_NUDGE, key, turnOptions)(sessionId);
|
|
43
|
+
if (!retry.error && !echoed(retry.text) && stripThinkingBlocks(retry.text)) {
|
|
44
|
+
Object.assign(result, retry);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (echoed(result.text)) {
|
|
48
|
+
log(`reasoning echo suppressed for ${where} (${String(result.text).length} chars)`);
|
|
49
|
+
return { text: '', echoed: true };
|
|
50
|
+
}
|
|
51
|
+
// The marker can survive inside an otherwise real reply; the chat never shows it.
|
|
52
|
+
return { text: stripThinkingBlocks(result.text), echoed: false };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { REPLY_NUDGE };
|
package/control/model-card.mjs
CHANGED
|
@@ -23,7 +23,7 @@ import { saveState, state } from '../core/state.mjs';
|
|
|
23
23
|
// missing binding here survived a green suite while every real tap died with
|
|
24
24
|
// "t is not defined": the router is the only caller that has to supply it.
|
|
25
25
|
import { t } from '../core/i18n.mjs';
|
|
26
|
-
import { send, tg, tgFast } from '../chat/telegram.mjs';
|
|
26
|
+
import { inlineKeyboard, send, tg, tgFast } from '../chat/telegram.mjs';
|
|
27
27
|
|
|
28
28
|
export const MODEL_PREFIX = 'md:';
|
|
29
29
|
/** Step one: the endpoint list. `md:!p` on its own asks for it again. */
|
|
@@ -372,12 +372,19 @@ export function modelPressRouter({ chatId, threadId, messageId, key, lang, answe
|
|
|
372
372
|
t,
|
|
373
373
|
say: async (text) => send(chatId, text, threadId),
|
|
374
374
|
answer,
|
|
375
|
-
redraw: (card) =>
|
|
376
|
-
|
|
375
|
+
redraw: (card) => {
|
|
376
|
+
// `card.keyboard` is this module's own shape: `{ text, data }`. Telegram
|
|
377
|
+
// knows only `callback_data`, and a button with `text` and no
|
|
378
|
+
// `callback_data` is refused with "Text buttons are not allowed in the
|
|
379
|
+
// inline keyboard" — the whole edit, not just that button. Sending the
|
|
380
|
+
// internal shape is why every endpoint tap since 1.19 left the card on
|
|
381
|
+
// step one. Convert, and never hand Telegram the raw rows.
|
|
382
|
+
const keyboard = inlineKeyboard(card.keyboard);
|
|
383
|
+
return tgFast('editMessageText', {
|
|
377
384
|
chat_id: chatId,
|
|
378
385
|
message_id: messageId,
|
|
379
386
|
text: card.text,
|
|
380
|
-
reply_markup: { inline_keyboard:
|
|
387
|
+
reply_markup: { inline_keyboard: keyboard },
|
|
381
388
|
...(threadId > 0 ? { message_thread_id: threadId } : {}),
|
|
382
389
|
}).catch(async (error) => {
|
|
383
390
|
// A refused edit used to be swallowed, which is how "the endpoint tap
|
|
@@ -388,12 +395,13 @@ export function modelPressRouter({ chatId, threadId, messageId, key, lang, answe
|
|
|
388
395
|
await tgFast('sendMessage', {
|
|
389
396
|
chat_id: chatId,
|
|
390
397
|
text: card.text,
|
|
391
|
-
reply_markup: { inline_keyboard:
|
|
398
|
+
reply_markup: { inline_keyboard: keyboard },
|
|
392
399
|
...(threadId > 0 ? { message_thread_id: threadId } : {}),
|
|
393
400
|
}).catch((sendError) => {
|
|
394
401
|
log(`model card resend failed for ${key}: ${sendError.message}`);
|
|
395
402
|
});
|
|
396
|
-
})
|
|
403
|
+
});
|
|
404
|
+
},
|
|
397
405
|
}).then((claimed) => {
|
|
398
406
|
if (claimed) log(`model press ${data} for ${key}`);
|
|
399
407
|
return claimed;
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# CHANGELOG — DSH Telegram bridge
|
|
2
2
|
|
|
3
|
+
## 1.38.3
|
|
4
|
+
|
|
5
|
+
- **The `/model` endpoint tap now reaches the model list.** The report was always
|
|
6
|
+
the same: tap an endpoint, nothing happens, the card stays on step one, and
|
|
7
|
+
there is no way to test a turn on another model without asking an agent to do
|
|
8
|
+
it by hand. The cause was one field name. `modelCard()` builds buttons as
|
|
9
|
+
`{ text, data }` — this module's own shape — and the redraw sent
|
|
10
|
+
`card.keyboard` straight to Telegram, which knows only `callback_data` and
|
|
11
|
+
rejects a button that has text and no payload with `can't parse
|
|
12
|
+
InlineKeyboardButton: Text buttons are not allowed in the inline keyboard`.
|
|
13
|
+
That rejects the whole edit, so the second step was built, sent, and refused
|
|
14
|
+
every time since the two-step card shipped. The redraw now converts with the
|
|
15
|
+
same `inlineKeyboard()` every other keyboard uses, and the re-send fallback
|
|
16
|
+
gets the converted rows too — a fallback carrying the bad shape fails for the
|
|
17
|
+
same reason the edit did.
|
|
18
|
+
- **The test asserts the wire shape, not the local one.** Twenty-five green tests
|
|
19
|
+
covered this card and none of them caught it, because they checked that the
|
|
20
|
+
keyboard had rows after building it in memory, where `data` is correct. The
|
|
21
|
+
press test now walks every button of the edit and of the re-sent message and
|
|
22
|
+
requires `callback_data`, at most 64 bytes, and no leftover `data` field — the
|
|
23
|
+
three things Telegram checks before it will draw anything.
|
|
24
|
+
|
|
3
25
|
## 1.38.2
|
|
4
26
|
|
|
5
27
|
- **A turn that ends without an answer asks once more instead of apologising.**
|