@goodandready/dsh-messenger-gateway 0.4.13 → 0.4.15
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/config.js +17 -1
- package/lib/file-manager.js +9 -0
- package/lib/gateway.js +6 -4
- package/lib/index.js +19 -13
- package/lib/stream.js +2 -1
- package/package.json +1 -1
package/lib/config.js
CHANGED
|
@@ -8,7 +8,7 @@ const HomeEntry = z.object({
|
|
|
8
8
|
|
|
9
9
|
export const PluginConfig = z.object({
|
|
10
10
|
enabled: z.boolean().volatile().default(true),
|
|
11
|
-
internalBaseURL: z.string().volatile().default('http://127.0.0.1:3080'),
|
|
11
|
+
internalBaseURL: z.string().volatile().default('').description('Internal base URL for host services; if omitted, resolved dynamically from webServer port or falls back to http://127.0.0.1:3080'),
|
|
12
12
|
defaultLocale: z.union([z.const('en'), z.const('zh')]).default('en').description('Default language for bot messages and notifications (en, zh)'),
|
|
13
13
|
telegram: z.object({
|
|
14
14
|
enabled: z.boolean().default(false),
|
|
@@ -113,3 +113,19 @@ export function plainConfig(value) {
|
|
|
113
113
|
if (typeof value.get === 'function') return plainConfig(value.get())
|
|
114
114
|
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, plainConfig(v)]))
|
|
115
115
|
}
|
|
116
|
+
|
|
117
|
+
export function resolveInternalBaseUrl(config = {}, ctx) {
|
|
118
|
+
const val = typeof config?.internalBaseURL?.get === 'function'
|
|
119
|
+
? config.internalBaseURL.get()
|
|
120
|
+
: config?.internalBaseURL
|
|
121
|
+
const raw = String(val || '').trim()
|
|
122
|
+
if (raw) return raw
|
|
123
|
+
const ws = ctx?.get?.('webServer') || ctx?.webServer
|
|
124
|
+
const rawPort = ws?.port ?? (typeof ws?.address === 'function' ? ws.address()?.port : null)
|
|
125
|
+
const port = Number(rawPort)
|
|
126
|
+
if (Number.isInteger(port) && port > 0 && port <= 65535) {
|
|
127
|
+
return `http://127.0.0.1:${port}`
|
|
128
|
+
}
|
|
129
|
+
return 'http://127.0.0.1:3080'
|
|
130
|
+
}
|
|
131
|
+
|
package/lib/file-manager.js
CHANGED
|
@@ -76,6 +76,15 @@ export function resolveSafePath(baseCwd, userPath = '.') {
|
|
|
76
76
|
return { base, target, relativePath: rel || '.' }
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Resolves candidate path strictly inside base directory (Issue #127).
|
|
81
|
+
* Throws ERR_PATH_TRAVERSAL if candidate escapes base (lexically, absolute, drive letter or symlink).
|
|
82
|
+
* Returns the resolved absolute target path.
|
|
83
|
+
*/
|
|
84
|
+
export function resolveInside(base, candidate = '.') {
|
|
85
|
+
return resolveSafePath(base, candidate).target
|
|
86
|
+
}
|
|
87
|
+
|
|
79
88
|
export async function listFiles(baseCwd, subPath = '.', opts = {}) {
|
|
80
89
|
const { maxEntries = 50, showHidden = false } = opts
|
|
81
90
|
const { base, target, relativePath } = resolveSafePath(baseCwd, subPath)
|
package/lib/gateway.js
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
collectDynamicSkills, syncTelegramCommands,
|
|
28
28
|
mirrorSessionToForumTopic, relayTurnToForumMirror,
|
|
29
29
|
} from './forum-mirror.js'
|
|
30
|
+
import { resolveInternalBaseUrl } from './config.js'
|
|
30
31
|
|
|
31
32
|
const PLUGIN = 'dsh-messenger-gateway'
|
|
32
33
|
|
|
@@ -142,8 +143,7 @@ export class Gateway {
|
|
|
142
143
|
setMuted(chatId, on) { return this.muted.set(chatId, on) }
|
|
143
144
|
|
|
144
145
|
baseUrl() {
|
|
145
|
-
|
|
146
|
-
return raw || 'http://127.0.0.1:3080'
|
|
146
|
+
return resolveInternalBaseUrl(this.config, this.ctx)
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
tg() { return this.config.telegram || {} }
|
|
@@ -207,13 +207,13 @@ export class Gateway {
|
|
|
207
207
|
collector.onStream?.(collector.streamText, collector.toolName)
|
|
208
208
|
}
|
|
209
209
|
} else if (event.type === 'tool/call') {
|
|
210
|
-
collector.toolName = extractToolName(event.data) || collector.toolName
|
|
210
|
+
collector.toolName = extractToolName(event.data || event) || collector.toolName
|
|
211
211
|
collector.onStream?.(collector.streamText || '', collector.toolName)
|
|
212
212
|
} else if (event.type === 'tool/result') {
|
|
213
213
|
collector.toolName = ''
|
|
214
214
|
collector.onStream?.(collector.streamText || '', '')
|
|
215
215
|
} else if (event.type === 'turn/end') {
|
|
216
|
-
collector.reason = event.data?.reason || event.data
|
|
216
|
+
collector.reason = event.data?.reason || event.reason || event.data
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
|
|
@@ -225,6 +225,8 @@ export class Gateway {
|
|
|
225
225
|
this.ctx.on('turn/start', (session, data) => onHost(session, { type: 'turn/start', data })),
|
|
226
226
|
this.ctx.on('assistant/message', (session, message) => onHost(session, { type: 'assistant/message', data: { message } })),
|
|
227
227
|
this.ctx.on('assistant/chunk', (session, chunk) => onHost(session, { type: 'assistant/chunk', data: { chunk } })),
|
|
228
|
+
this.ctx.on('tool/call', (session, data) => onHost(session, { type: 'tool/call', data })),
|
|
229
|
+
this.ctx.on('tool/result', (session, data) => onHost(session, { type: 'tool/result', data })),
|
|
228
230
|
]
|
|
229
231
|
this.disposeListener = () => {
|
|
230
232
|
for (const un of unsubs) {
|
package/lib/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from './messenger-api.js'
|
|
12
12
|
import { listHomes } from './homes.js'
|
|
13
13
|
export { plainConfig } from './config.js'
|
|
14
|
-
import { Config, plainConfig } from './config.js'
|
|
14
|
+
import { Config, plainConfig, resolveInternalBaseUrl } from './config.js'
|
|
15
15
|
import { setupSettings } from './settings-bridge.js'
|
|
16
16
|
|
|
17
17
|
export const name = '@goodandready/dsh-messenger-gateway'
|
|
@@ -31,10 +31,11 @@ function resolveConfig(raw) {
|
|
|
31
31
|
return cfg
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function publicConfig(cfg) {
|
|
34
|
+
function publicConfig(cfg, gw, ctx) {
|
|
35
|
+
const internalBaseURL = gw?.baseUrl?.() || resolveInternalBaseUrl(cfg, ctx)
|
|
35
36
|
return {
|
|
36
37
|
enabled: cfg.enabled,
|
|
37
|
-
internalBaseURL
|
|
38
|
+
internalBaseURL,
|
|
38
39
|
telegram: {
|
|
39
40
|
enabled: cfg.telegram.enabled,
|
|
40
41
|
allowedUserIds: cfg.telegram.allowedUserIds,
|
|
@@ -342,13 +343,18 @@ export function apply(ctx, config) {
|
|
|
342
343
|
const gw = getGw()
|
|
343
344
|
if (gw) gw.syncTelegramCommands().catch((err) => ctx.logger?.debug?.(`sync telegram commands on skills change: ${err?.message || err}`))
|
|
344
345
|
}
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
346
|
+
const unbinds = [
|
|
347
|
+
ctx.on('tools/change', onSkillsChange),
|
|
348
|
+
ctx.on('tools/update', onSkillsChange),
|
|
349
|
+
ctx.on('tools/updated', onSkillsChange),
|
|
350
|
+
ctx.on('skills/change', onSkillsChange),
|
|
351
|
+
ctx.on('skills/updated', onSkillsChange),
|
|
352
|
+
ctx.on('skills/update', onSkillsChange),
|
|
353
|
+
]
|
|
348
354
|
return () => {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
355
|
+
for (const un of unbinds) {
|
|
356
|
+
if (typeof un === 'function') un()
|
|
357
|
+
}
|
|
352
358
|
}
|
|
353
359
|
}, 'dsh-messenger-gateway: dynamic skills sync')
|
|
354
360
|
|
|
@@ -371,7 +377,7 @@ export function apply(ctx, config) {
|
|
|
371
377
|
if (event.type !== 'turn/end') return
|
|
372
378
|
const prefixes = cfg.excludeSessionPrefixes || ['msgw-']
|
|
373
379
|
if (isExcludedSession(session.id, prefixes)) return
|
|
374
|
-
const reason = event.data?.reason
|
|
380
|
+
const reason = event.data?.reason || event.reason || event.data
|
|
375
381
|
const kind = reason?.kind === 'completed' ? 'task_done' : 'error'
|
|
376
382
|
const events = new Set(cfg.events?.length ? cfg.events : ['task_done', 'error'])
|
|
377
383
|
if (!events.has(kind)) return
|
|
@@ -439,7 +445,7 @@ export function apply(ctx, config) {
|
|
|
439
445
|
consecutiveFailures: gw?.consecutiveApiFailures || 0,
|
|
440
446
|
lastError: gw?.lastApiError || null,
|
|
441
447
|
},
|
|
442
|
-
config: publicConfig(source()),
|
|
448
|
+
config: publicConfig(source(), gw, ctx),
|
|
443
449
|
})
|
|
444
450
|
},
|
|
445
451
|
}), 'dsh-messenger-gateway: status')
|
|
@@ -523,7 +529,7 @@ export function apply(ctx, config) {
|
|
|
523
529
|
ctx.effect(() => getWebServer().register({
|
|
524
530
|
kind: 'exact', path: '/dsh-messenger-gateway/config',
|
|
525
531
|
handler: async (req, res) => {
|
|
526
|
-
if (req.method === 'GET') return writeJson(res, 200, { ok: true, config: publicConfig(source()) })
|
|
532
|
+
if (req.method === 'GET') return writeJson(res, 200, { ok: true, config: publicConfig(source(), getGw(), ctx) })
|
|
527
533
|
if (req.method !== 'PUT') return writeJson(res, 405, { ok: false, error: 'GET or PUT' })
|
|
528
534
|
if (!isTrustedSettingsRequest(req, source().webhooks?.secret)) return writeJson(res, 403, { ok: false, error: 'forbidden' })
|
|
529
535
|
if (!settingsApi?.isReady?.()) return writeJson(res, 503, { ok: false, error: 'settings not ready' })
|
|
@@ -556,7 +562,7 @@ export function apply(ctx, config) {
|
|
|
556
562
|
media: { ...cur.media, ...(payload.media || {}) },
|
|
557
563
|
}))
|
|
558
564
|
sync()
|
|
559
|
-
writeJson(res, 200, { ok: true, config: publicConfig(source()) })
|
|
565
|
+
writeJson(res, 200, { ok: true, config: publicConfig(source(), getGw(), ctx) })
|
|
560
566
|
} catch (err) {
|
|
561
567
|
writeJson(res, 400, { ok: false, error: err.message })
|
|
562
568
|
}
|
package/lib/stream.js
CHANGED
|
@@ -11,7 +11,8 @@ export function extractTextDelta(chunk) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function extractToolName(eventData) {
|
|
14
|
-
|
|
14
|
+
if (typeof eventData === 'string') return eventData
|
|
15
|
+
const name = eventData?.tool?.name || eventData?.toolName || eventData?.name || eventData?.tool
|
|
15
16
|
return name ? String(name) : ''
|
|
16
17
|
}
|
|
17
18
|
|
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.15",
|
|
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",
|