dsh-channel-feishu 0.9.3 → 0.9.5

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/index.js +57 -13
  3. 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.3/dsh-channel-feishu-0.9.3.tgz
85
+ dsh plugin add https://github.com/Poy-Coder/dsh-channel-feishu/releases/download/v0.9.5/dsh-channel-feishu-0.9.5.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, prefixed with 其他端.'),
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
- if (!turns.has(record.key)) return
431
- if (record.phase !== 'thinking' || !record.card) return
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: `👤 其他端:${clipped}` })
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: randomUUID(),
1870
+ id: promptId,
1851
1871
  role: 'user',
1852
1872
  content: [{ type: 'text', text: inboundUserText(firstMessage) }],
1853
1873
  source: { kind: 'user' },
@@ -2155,14 +2175,21 @@ export async function handleInboundEvent(ctx, config, data, seen) {
2155
2175
  const inbound = provider().parseInbound(data)
2156
2176
  if (!inbound) return
2157
2177
  const eventId = inbound.dedupeKey
2158
- if (eventId) {
2159
- if (seen.has(eventId)) return
2178
+ if (eventId && seen.has(eventId)) return
2179
+ // Mark an event only once it is settled. Marking before delivery loses the
2180
+ // message for good: a restart between the write and the followup leaves the id
2181
+ // "seen", so Feishu's redelivery is dropped silently.
2182
+ const markSeen = () => {
2183
+ if (!eventId) return
2160
2184
  seen.add(eventId)
2161
2185
  if (seen.size > INBOUND_DEDUPE_LIMIT) seen.delete(seen.values().next().value)
2162
2186
  persistSeenEvents(config, seen)
2163
2187
  }
2164
2188
 
2165
- if (inbound.senderType === 'app') return
2189
+ if (inbound.senderType === 'app') {
2190
+ markSeen()
2191
+ return
2192
+ }
2166
2193
 
2167
2194
  const senderId = inbound.senderId
2168
2195
  const allowed = Array.isArray(config.allowedUsers)
@@ -2171,6 +2198,7 @@ export async function handleInboundEvent(ctx, config, data, seen) {
2171
2198
  if (allowed.length > 0 && !allowed.includes(senderId)) {
2172
2199
  warnTo(ctx, `ignored message from ${senderId}: not in allowedUsers`)
2173
2200
  log({ event: 'inbound', result: 'dropped', reason: 'sender not in allowedUsers', senderId })
2201
+ markSeen()
2174
2202
  return
2175
2203
  }
2176
2204
 
@@ -2178,6 +2206,7 @@ export async function handleInboundEvent(ctx, config, data, seen) {
2178
2206
  if (inbound.unsupported) {
2179
2207
  warnTo(ctx, `ignored unsupported message_type=${inbound.unsupported}`)
2180
2208
  log({ event: 'inbound', result: 'dropped', reason: `non-text message_type=${inbound.unsupported}`, senderId })
2209
+ markSeen()
2181
2210
  return
2182
2211
  }
2183
2212
 
@@ -2229,6 +2258,7 @@ export async function handleInboundEvent(ctx, config, data, seen) {
2229
2258
 
2230
2259
  if (!text) {
2231
2260
  log({ event: 'inbound', result: 'dropped', reason: 'empty text', senderId, chatId })
2261
+ markSeen()
2232
2262
  return
2233
2263
  }
2234
2264
  // Control phrases are consumed here, never delivered to the model.
@@ -2239,12 +2269,16 @@ export async function handleInboundEvent(ctx, config, data, seen) {
2239
2269
  const command = parseSlashCommand(text)
2240
2270
  if (command) {
2241
2271
  await handleSlashCommand(ctx, config, { ...command, chatId, senderId })
2272
+ markSeen()
2242
2273
  return
2243
2274
  }
2244
2275
 
2245
2276
  // A pending question owns the next reply in its chat: a numbered, labelled or
2246
2277
  // free-text answer settles the tool call instead of starting a new turn.
2247
- if (consumeQuestionTextAnswer(ctx, config, { chatId, senderId, text })) return
2278
+ if (consumeQuestionTextAnswer(ctx, config, { chatId, senderId, text })) {
2279
+ markSeen()
2280
+ return
2281
+ }
2248
2282
 
2249
2283
  let sessionId = currentSessionId(config)
2250
2284
  if (!sessionId) {
@@ -2255,6 +2289,7 @@ export async function handleInboundEvent(ctx, config, data, seen) {
2255
2289
  event: 'inbound', result: 'dropped',
2256
2290
  reason: 'no sessionId configured (set sessionMode: create to bootstrap one)', senderId, chatId,
2257
2291
  })
2292
+ markSeen()
2258
2293
  return
2259
2294
  }
2260
2295
  // Fresh install: the bundle row carries no sessionId. Create the channel's
@@ -2262,6 +2297,7 @@ export async function handleInboundEvent(ctx, config, data, seen) {
2262
2297
  // instead of dropping it — otherwise a new install looks connected but deaf.
2263
2298
  log({ event: 'inbound', result: 'bootstrap', reason: 'no session yet; creating one', senderId, chatId })
2264
2299
  await switchToNewSession(ctx, config, { chatId, senderId, firstMessage: text })
2300
+ markSeen()
2265
2301
  return
2266
2302
  }
2267
2303
 
@@ -2269,6 +2305,7 @@ export async function handleInboundEvent(ctx, config, data, seen) {
2269
2305
  if (!resolved.agent) {
2270
2306
  warnTo(ctx, `inbound message dropped for session "${sessionId}": ${resolved.reason}`)
2271
2307
  log({ event: 'inbound', result: 'dropped', reason: resolved.reason, senderId, chatId, sessionId })
2308
+ markSeen()
2272
2309
  return
2273
2310
  }
2274
2311
 
@@ -2293,6 +2330,8 @@ export async function handleInboundEvent(ctx, config, data, seen) {
2293
2330
  content: [{ type: 'text', text: inboundUserText(text) }],
2294
2331
  source: { kind: 'user' },
2295
2332
  })
2333
+ // Delivered: only now is it safe to remember the event and drop redeliveries.
2334
+ markSeen()
2296
2335
  rememberChat(config, sessionId, { chatId, senderId })
2297
2336
  // Acknowledge on the user's own message: the cheapest "I got it" there is.
2298
2337
  if (config.reactions !== false && inbound.messageId) {
@@ -3088,9 +3127,11 @@ function startInbound(ctx, config) {
3088
3127
  if (!sessionId || sessionId !== activeSessionId(config)) return
3089
3128
  const message = payload?.message
3090
3129
  if (!message?.id || channelPromptIds.has(message.id)) return
3130
+ // Only messages a person typed on another surface are mirrored:
3131
+ // schedule reminders and injected context snapshots are not conversation.
3132
+ if (String(message.source?.kind ?? 'user') !== 'user') return
3091
3133
  const text = textOfMessage(message)
3092
3134
  if (!text.trim()) return
3093
- // Scheduled reminders are injected as user messages; they are not typed.
3094
3135
  if (/^\[SCHEDULE REMINDER/i.test(text.trim())) return
3095
3136
  void mirrorUserMessage(config, sessionId, text)
3096
3137
  })
@@ -3162,7 +3203,10 @@ export function apply(ctx, config = {}) {
3162
3203
  log: (record) => logInbound(config, record),
3163
3204
  credentials: typeof ctx.get === 'function' ? ctx.get('credentials') : undefined,
3164
3205
  })
3165
- ctx.effect?.(() => () => { activeProvider = undefined })
3206
+ ctx.effect?.(() => () => {
3207
+ activeProvider = undefined
3208
+ disposeTurnTimers()
3209
+ })
3166
3210
  ctx.tools.register(sendMessageTool(config))
3167
3211
  ctx.tools.register(sendFileTool(config))
3168
3212
  ctx.tools.register(statusTool(config))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-channel-feishu",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "type": "module",
5
5
  "description": "Feishu/Lark (椋炰功) channel for DeepSeek Harness: a chat bound to a DSH session, with streaming cards and attachments.",
6
6
  "license": "MIT",