@goodandready/dsh-messenger-gateway 0.4.20 → 0.4.21
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/lib/commands.js +3 -2
- package/lib/forum-mirror.js +21 -18
- package/lib/gateway-commands.js +2 -1
- package/lib/gateway.js +7 -3
- package/lib/text.js +18 -0
- package/package.json +1 -1
package/lib/commands.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { truncateSafe } from "./text.js"
|
|
1
2
|
export const DEFAULT_TELEGRAM_COMMANDS = [
|
|
2
3
|
{ command: 'start', description: 'Connect and show greeting' },
|
|
3
4
|
{ command: 'help', description: 'Show commands help' },
|
|
@@ -46,7 +47,7 @@ export function normalizeTelegramCommands(commands) {
|
|
|
46
47
|
command = command.slice(0, 32).toLowerCase()
|
|
47
48
|
if (seen.has(command)) continue
|
|
48
49
|
seen.add(command)
|
|
49
|
-
out.push({ command, description: description
|
|
50
|
+
out.push({ command, description: truncateSafe(description, 256) })
|
|
50
51
|
}
|
|
51
52
|
return out.length ? out : [...DEFAULT_TELEGRAM_COMMANDS]
|
|
52
53
|
}
|
|
@@ -65,7 +66,7 @@ export function mergeDynamicCommands(baseCommands = DEFAULT_TELEGRAM_COMMANDS, d
|
|
|
65
66
|
if (!command || seen.has(command)) continue
|
|
66
67
|
let description = String(item.description || item.title || `Skill ${command}`).trim()
|
|
67
68
|
if (!description) description = `Skill ${command}`
|
|
68
|
-
description = description
|
|
69
|
+
description = truncateSafe(description, 256)
|
|
69
70
|
seen.add(command)
|
|
70
71
|
out.push({ command, description })
|
|
71
72
|
}
|
package/lib/forum-mirror.js
CHANGED
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
import { mergeDynamicCommands } from './commands.js'
|
|
2
2
|
import { t } from './locales/index.js'
|
|
3
|
-
import { stripReasoningPreamble, splitText } from './text.js'
|
|
3
|
+
import { stripReasoningPreamble, splitText, truncateSafe } from './text.js'
|
|
4
4
|
import { stripImageUrls } from './outbound.js'
|
|
5
5
|
|
|
6
|
-
export function collectDynamicSkills(ctx) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
export async function collectDynamicSkills(ctx) {
|
|
7
|
+
const skills = []
|
|
8
|
+
try {
|
|
9
|
+
const skillsService = ctx?.get ? ctx.get("skills") : ctx?.skills
|
|
10
|
+
if (!skillsService) return skills
|
|
11
|
+
const rawSkills = typeof skillsService.list === "function" ? skillsService.list() : []
|
|
12
|
+
const allSkills = (rawSkills && typeof rawSkills.then === "function") ? await rawSkills : (rawSkills || [])
|
|
13
|
+
for (const s of allSkills) {
|
|
14
|
+
if (!s || !s.name) continue
|
|
15
|
+
if (s.invocation?.userInvocable === false || s.userInvocable === false) continue
|
|
16
|
+
const rawDesc = String(s.description || s.title || `Skill ${s.name}`).trim()
|
|
17
|
+
skills.push({
|
|
18
|
+
name: String(s.name),
|
|
19
|
+
description: truncateSafe(rawDesc || `Skill ${s.name}`, 80),
|
|
20
|
+
})
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
} catch (err) {
|
|
23
|
+
ctx?.logger?.debug?.(`Failed to collect dynamic skills: ${err?.message || err}`)
|
|
23
24
|
}
|
|
25
|
+
return skills
|
|
26
|
+
}
|
|
24
27
|
export async function syncTelegramCommands(gw) {
|
|
25
28
|
const tgAdapter = gw.adapters.get('telegram')
|
|
26
29
|
if (!tgAdapter || typeof tgAdapter.registerCommands !== 'function') return
|
|
27
30
|
const baseCommands = gw.config.telegram?.commands || []
|
|
28
|
-
const dynamicSkills = collectDynamicSkills(gw.ctx)
|
|
31
|
+
const dynamicSkills = await collectDynamicSkills(gw.ctx)
|
|
29
32
|
const merged = mergeDynamicCommands(baseCommands, dynamicSkills, 100)
|
|
30
33
|
try {
|
|
31
34
|
await tgAdapter.registerCommands(merged)
|
package/lib/gateway-commands.js
CHANGED
|
@@ -601,5 +601,6 @@ export async function handleGatewayCommand(gw, key, text, input) {
|
|
|
601
601
|
return reply(t('msg.muted_off', {}, locale))
|
|
602
602
|
}
|
|
603
603
|
|
|
604
|
-
|
|
604
|
+
// Unrecognized slash command: let it pass through to the underlying DSH agent (runtime commands, skills)
|
|
605
|
+
return { forwardToAgent: true }
|
|
605
606
|
}
|
package/lib/gateway.js
CHANGED
|
@@ -390,7 +390,10 @@ export class Gateway {
|
|
|
390
390
|
let attachments = [...(input.attachments || [])]
|
|
391
391
|
const hasMedia = attachments.length > 0
|
|
392
392
|
if (!body && !hasMedia) return
|
|
393
|
-
if (body.startsWith('/')) {
|
|
393
|
+
if (body.startsWith('/')) {
|
|
394
|
+
const cmdResult = await this.handleCommand(key, body, input)
|
|
395
|
+
if (!cmdResult?.forwardToAgent) return
|
|
396
|
+
}
|
|
394
397
|
try {
|
|
395
398
|
const chat = await this.getOrCreateChat(key, input)
|
|
396
399
|
const photoOnlyMode = this.config.agent?.photoOnlyMode ?? 'prompt'
|
|
@@ -418,7 +421,8 @@ export class Gateway {
|
|
|
418
421
|
break
|
|
419
422
|
}
|
|
420
423
|
}
|
|
421
|
-
const
|
|
424
|
+
const cleanBody = body.replace(/^(\/[a-zA-Z0-9_]+)@[a-zA-Z0-9_]+(?=\s|$)/, '$1')
|
|
425
|
+
const turnInput = { ...input, text: cleanBody, attachments, inboundWasVoice, personaOverride }
|
|
422
426
|
|
|
423
427
|
// Hermes-like steer: while a turn is running, inject followup instead of abort+restart
|
|
424
428
|
if (this.isChatBusy(chat)) {
|
|
@@ -468,7 +472,7 @@ export class Gateway {
|
|
|
468
472
|
return handleGatewayCommand(this, key, text, input)
|
|
469
473
|
}
|
|
470
474
|
|
|
471
|
-
collectDynamicSkills() {
|
|
475
|
+
async collectDynamicSkills() {
|
|
472
476
|
return collectDynamicSkills(this.ctx)
|
|
473
477
|
}
|
|
474
478
|
|
package/lib/text.js
CHANGED
|
@@ -37,3 +37,21 @@ export function stripReasoningPreamble(text) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export const MESSENGER_RELAY_INSTRUCTION = 'Channel: Messenger. Reply concisely and directly to the user. Do not leak internal reasoning or planning traces.'
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Truncate string to maxLen without splitting UTF-16 surrogate pairs.
|
|
43
|
+
* If the cut falls on a high surrogate, drops the high surrogate so the string is well-formed.
|
|
44
|
+
*/
|
|
45
|
+
export function truncateSafe(str, maxLen = 80) {
|
|
46
|
+
const raw = String(str ?? '')
|
|
47
|
+
if (raw.length <= maxLen) return raw
|
|
48
|
+
let sliced = raw.slice(0, maxLen)
|
|
49
|
+
const lastCode = sliced.charCodeAt(sliced.length - 1)
|
|
50
|
+
if (lastCode >= 0xD800 && lastCode <= 0xDBFF) {
|
|
51
|
+
sliced = sliced.slice(0, -1)
|
|
52
|
+
}
|
|
53
|
+
if (typeof sliced.isWellFormed === 'function' && !sliced.isWellFormed()) {
|
|
54
|
+
sliced = sliced.replace(/[\uD800-\uDFFF]+$/, '')
|
|
55
|
+
}
|
|
56
|
+
return sliced
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-messenger-gateway",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.21",
|
|
4
4
|
"description": "Telegram messenger bridge for DeepSeek Harness: sessions, steer, homes, inline asks, notify bridge, and optional TTS voice notes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|