dsh-channel-feishu 0.9.6 → 0.9.7

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 +45 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -25,7 +25,7 @@ dsh plugin add dsh-channel-feishu
25
25
 
26
26
  ```bash
27
27
  dsh plugin add https://github.com/Poy-Coder/dsh-channel-feishu
28
- dsh plugin add https://github.com/Poy-Coder/dsh-channel-feishu/releases/download/v0.9.6/dsh-channel-feishu-0.9.6.tgz
28
+ dsh plugin add https://github.com/Poy-Coder/dsh-channel-feishu/releases/download/v0.9.7/dsh-channel-feishu-0.9.7.tgz
29
29
  ```
30
30
 
31
31
  依赖必须用扁平结构装(非 ASCII 目录下 pnpm 的软链会把路径写坏):`pnpm install --node-linker=hoisted`。
package/index.js CHANGED
@@ -368,8 +368,22 @@ function replyText(record) {
368
368
  return `${joined.slice(0, MAX_REPLY_CHARS)}\n\n…(内容过长,已截断)`
369
369
  }
370
370
 
371
- function summaryOf(text) {
372
- const line = String(text ?? '').split('\n').map((value) => value.trim()).find(Boolean) ?? 'DSH'
371
+ /**
372
+ * Last-resort plain-text rendering: a text message is not markdown, so the
373
+ * fallback strips the syntax instead of showing `**bold**` and `## heading`.
374
+ */
375
+ export function plainTextFromMarkdown(text) {
376
+ return String(text ?? '')
377
+ .replace(/^#{1,6}\s+/gm, '')
378
+ .replace(/\*\*([^*]+)\*\*/g, '$1')
379
+ .replace(/__([^_]+)__/g, '$1')
380
+ .replace(/`{1,3}([^`]+)`{1,3}/g, '$1')
381
+ .replace(/^\s*[-*]\s+/gm, '· ')
382
+ .replace(/^\s*>\s?/gm, '')
383
+ .trim()
384
+ }
385
+
386
+ function summaryOf(text) { const line = String(text ?? '').split('\n').map((value) => value.trim()).find(Boolean) ?? 'DSH'
373
387
  return line.length > 40 ? `${line.slice(0, 40)}…` : line
374
388
  }
375
389
 
@@ -471,6 +485,9 @@ function scheduleCardFlush(record, ctx, config) {
471
485
 
472
486
  const isRateLimited = (error) => /230020|frequency limit|rate limit/i.test(String(error?.message ?? error))
473
487
 
488
+ /** Feishu closes a streaming card after a while; further element writes get 300309. */
489
+ const isStreamingClosed = (error) => /300309|streaming mode is closed/i.test(String(error?.message ?? error))
490
+
474
491
  async function flushCard(record, ctx, config) {
475
492
  flushRan += 1
476
493
  const text = replyText(record)
@@ -513,9 +530,22 @@ async function flushCard(record, ctx, config) {
513
530
  logInbound(config, {
514
531
  event: 'card', result: 'rate-limited', sessionId: record.sessionId, turn: record.turn, sequence: card.sequence,
515
532
  })
533
+ } else if (isStreamingClosed(error) && (record.recreations ?? 0) < 3) {
534
+ // Feishu closes a streaming card after roughly ten minutes; a long turn
535
+ // then loses its card. Start a fresh one and keep writing there instead of
536
+ // degrading to a plain-text message (which would print raw markdown).
537
+ record.recreations = (record.recreations ?? 0) + 1
538
+ record.card = undefined
539
+ record.lastCardText = ''
540
+ record.backoffUntil = Date.now() + 1_000
541
+ logInbound(config, {
542
+ event: 'card', result: 'streaming-closed', sessionId: record.sessionId, turn: record.turn,
543
+ recreation: record.recreations, reason: errorText(error),
544
+ })
545
+ scheduleCardFlush(record, ctx, config)
516
546
  } else {
517
547
  record.cardFailed = true
518
- warnTo(ctx, `card text update failed, will fall back to text: ${errorText(error)}`)
548
+ warnTo(ctx, `card text update failed: ${errorText(error)}`)
519
549
  logInbound(config, {
520
550
  event: 'card', result: 'update-failed', sessionId: record.sessionId, turn: record.turn, reason: errorText(error),
521
551
  })
@@ -698,8 +728,18 @@ export async function finalizeTurn(ctx, config, sessionId, turn, reason) {
698
728
  })
699
729
  return
700
730
  } catch (error) {
701
- warnTo(ctx, `card finalize failed, falling back to text: ${errorText(error)}`)
731
+ warnTo(ctx, `card finalize failed: ${errorText(error)}`)
702
732
  logInbound(config, { event: 'card', result: 'close-failed', sessionId, turn, reason: errorText(error) })
733
+ // A dead streaming card (Feishu closes them after ~10 minutes) must not
734
+ // degrade to a plain-text message: markdown would show up as raw source.
735
+ // Post the answer as its own fresh card instead.
736
+ const posted = await postAnswerBelow(ctx, config, chatId, record, text)
737
+ if (posted) {
738
+ logInbound(config, {
739
+ event: 'card', result: 'reposted', sessionId, turn, cardId: posted, chars: text.length,
740
+ })
741
+ return
742
+ }
703
743
  }
704
744
  }
705
745
  }
@@ -715,7 +755,7 @@ export async function finalizeTurn(ctx, config, sessionId, turn, reason) {
715
755
  return
716
756
  }
717
757
  try {
718
- await sendChannelText(config, chatId, text)
758
+ await sendChannelText(config, chatId, plainTextFromMarkdown(text))
719
759
  logInbound(config, { event: 'reply', result: 'sent', sessionId, turn, chatId, chars: text.length })
720
760
  } catch (error) {
721
761
  warnTo(ctx, `reply delivery failed: ${errorText(error)}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-channel-feishu",
3
- "version": "0.9.6",
3
+ "version": "0.9.7",
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",