dsh-channel-feishu 0.9.3 → 0.9.4
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 +1 -1
- package/index.js +34 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -82,7 +82,7 @@ dsh plugin add dsh-channel-feishu
|
|
|
82
82
|
|
|
83
83
|
```bash
|
|
84
84
|
dsh plugin add https://github.com/Poy-Coder/dsh-channel-feishu
|
|
85
|
-
dsh plugin add https://github.com/Poy-Coder/dsh-channel-feishu/releases/download/v0.9.
|
|
85
|
+
dsh plugin add https://github.com/Poy-Coder/dsh-channel-feishu/releases/download/v0.9.4/dsh-channel-feishu-0.9.4.tgz
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
依赖必须用扁平结构装(非 ASCII 目录下 pnpm 的软链会把路径写坏):
|
package/index.js
CHANGED
|
@@ -92,7 +92,7 @@ export const Config = z.object({
|
|
|
92
92
|
defaultChatId: z.string().default('').description('Destination used when a tool call omits receiveId.'),
|
|
93
93
|
logFile: z.string().default('').description('Inbound diagnostics log path.'),
|
|
94
94
|
readyNotice: z.boolean().default(true).description('Send one "channel ready" message to the default chat after the inbound long connection comes up.'),
|
|
95
|
-
mirrorUserMessages: z.boolean().default(true).description('Post messages typed outside Feishu (desktop GUI) into the owning chat,
|
|
95
|
+
mirrorUserMessages: z.boolean().default(true).description('Post messages typed outside Feishu (desktop GUI) into the owning chat, as "来自桌面端:<text>".'),
|
|
96
96
|
logLevel: z.union([z.const('debug'), z.const('info'), z.const('warn'), z.const('error')])
|
|
97
97
|
.default('info')
|
|
98
98
|
.description('Minimum severity written to the diagnostics log.'),
|
|
@@ -427,14 +427,28 @@ async function ensureCard(record, ctx, config) {
|
|
|
427
427
|
function startProgressHeartbeat(record, ctx, config) {
|
|
428
428
|
if (record.heartbeat) return
|
|
429
429
|
const timer = setInterval(() => {
|
|
430
|
-
|
|
431
|
-
|
|
430
|
+
// Stop the moment this turn is no longer live: a disposed plugin leaves its
|
|
431
|
+
// records behind, and a surviving 10 s heartbeat would log forever.
|
|
432
|
+
if (!turns.has(record.key) || record.cardFailed || !record.card || record.phase !== 'thinking') {
|
|
433
|
+
clearInterval(timer)
|
|
434
|
+
if (record.heartbeat === timer) record.heartbeat = undefined
|
|
435
|
+
return
|
|
436
|
+
}
|
|
432
437
|
scheduleCardFlush(record, ctx, config)
|
|
433
438
|
}, PROGRESS_HEARTBEAT_MS)
|
|
434
439
|
timer.unref?.()
|
|
435
440
|
record.heartbeat = timer
|
|
436
441
|
}
|
|
437
442
|
|
|
443
|
+
/** Drop every per-turn timer; a disposed plugin must leave nothing ticking. */
|
|
444
|
+
function disposeTurnTimers() {
|
|
445
|
+
for (const record of turns.values()) {
|
|
446
|
+
if (record.timer) { clearTimeout(record.timer); record.timer = undefined }
|
|
447
|
+
if (record.heartbeat) { clearInterval(record.heartbeat); record.heartbeat = undefined }
|
|
448
|
+
}
|
|
449
|
+
turns.clear()
|
|
450
|
+
}
|
|
451
|
+
|
|
438
452
|
/** Coalesce stream deltas: one Feishu write per CARD_FLUSH_MS at most. */
|
|
439
453
|
function scheduleCardFlush(record, ctx, config) {
|
|
440
454
|
if (record.timer) return
|
|
@@ -1488,16 +1502,17 @@ const channelPromptIds = new Set()
|
|
|
1488
1502
|
|
|
1489
1503
|
/**
|
|
1490
1504
|
* Mirror a message typed outside Feishu (desktop GUI) into the owning chat, so
|
|
1491
|
-
* one conversation can be followed from either surface.
|
|
1505
|
+
* one conversation can be followed from either surface. The label names the
|
|
1506
|
+
* surface only: the body follows as-is.
|
|
1492
1507
|
*/
|
|
1493
|
-
async function mirrorUserMessage(config, sessionId, text) {
|
|
1508
|
+
async function mirrorUserMessage(config, sessionId, text, surface = '桌面端') {
|
|
1494
1509
|
const chatId = replyTargetOf(config, sessionId)
|
|
1495
1510
|
if (!chatId) return
|
|
1496
1511
|
const body = String(text ?? '').trim()
|
|
1497
1512
|
if (!body) return
|
|
1498
1513
|
const clipped = body.length > 2000 ? `${body.slice(0, 2000)}…` : body
|
|
1499
1514
|
try {
|
|
1500
|
-
await provider().sendText({ chatId, text:
|
|
1515
|
+
await provider().sendText({ chatId, text: `来自${surface}:${clipped}` })
|
|
1501
1516
|
logInbound(config, { event: 'mirror', result: 'sent', sessionId, chatId })
|
|
1502
1517
|
} catch (error) {
|
|
1503
1518
|
logInbound(config, { event: 'mirror', result: 'failed', sessionId, reason: errorText(error) })
|
|
@@ -1846,8 +1861,13 @@ async function switchToNewSession(ctx, config, { chatId, senderId, firstMessage
|
|
|
1846
1861
|
|
|
1847
1862
|
if (firstMessage) {
|
|
1848
1863
|
try {
|
|
1864
|
+
// Track the id: an untracked prompt would be mirrored back into the chat
|
|
1865
|
+
// as if it came from another surface — the very first message included.
|
|
1866
|
+
const promptId = randomUUID()
|
|
1867
|
+
channelPromptIds.add(promptId)
|
|
1868
|
+
if (channelPromptIds.size > 200) channelPromptIds.delete(channelPromptIds.values().next().value)
|
|
1849
1869
|
await handle.agent.followup({
|
|
1850
|
-
id:
|
|
1870
|
+
id: promptId,
|
|
1851
1871
|
role: 'user',
|
|
1852
1872
|
content: [{ type: 'text', text: inboundUserText(firstMessage) }],
|
|
1853
1873
|
source: { kind: 'user' },
|
|
@@ -3088,9 +3108,11 @@ function startInbound(ctx, config) {
|
|
|
3088
3108
|
if (!sessionId || sessionId !== activeSessionId(config)) return
|
|
3089
3109
|
const message = payload?.message
|
|
3090
3110
|
if (!message?.id || channelPromptIds.has(message.id)) return
|
|
3111
|
+
// Only messages a person typed on another surface are mirrored:
|
|
3112
|
+
// schedule reminders and injected context snapshots are not conversation.
|
|
3113
|
+
if (String(message.source?.kind ?? 'user') !== 'user') return
|
|
3091
3114
|
const text = textOfMessage(message)
|
|
3092
3115
|
if (!text.trim()) return
|
|
3093
|
-
// Scheduled reminders are injected as user messages; they are not typed.
|
|
3094
3116
|
if (/^\[SCHEDULE REMINDER/i.test(text.trim())) return
|
|
3095
3117
|
void mirrorUserMessage(config, sessionId, text)
|
|
3096
3118
|
})
|
|
@@ -3162,7 +3184,10 @@ export function apply(ctx, config = {}) {
|
|
|
3162
3184
|
log: (record) => logInbound(config, record),
|
|
3163
3185
|
credentials: typeof ctx.get === 'function' ? ctx.get('credentials') : undefined,
|
|
3164
3186
|
})
|
|
3165
|
-
ctx.effect?.(() => () => {
|
|
3187
|
+
ctx.effect?.(() => () => {
|
|
3188
|
+
activeProvider = undefined
|
|
3189
|
+
disposeTurnTimers()
|
|
3190
|
+
})
|
|
3166
3191
|
ctx.tools.register(sendMessageTool(config))
|
|
3167
3192
|
ctx.tools.register(sendFileTool(config))
|
|
3168
3193
|
ctx.tools.register(statusTool(config))
|
package/package.json
CHANGED