@xmanrui/dsh-im 2.3.0 → 2.5.0

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 (57) hide show
  1. package/README.en.md +9 -4
  2. package/README.md +9 -4
  3. package/lib/client.js +411 -156
  4. package/lib/index.js +218 -210
  5. package/package.json +1 -1
  6. package/plugin-src/client/channel-card-meta.js +36 -1
  7. package/plugin-src/client/channels/dingtalk/api.js +2 -0
  8. package/plugin-src/client/channels/dingtalk/index.js +9 -1
  9. package/plugin-src/client/channels/feishu/api.js +3 -0
  10. package/plugin-src/client/channels/feishu/index.js +46 -28
  11. package/plugin-src/client/channels/feishu/styles.js +26 -1
  12. package/plugin-src/client/channels/qq/api.js +2 -0
  13. package/plugin-src/client/channels/qq/index.js +9 -1
  14. package/plugin-src/client/channels/shared/token-api.js +2 -0
  15. package/plugin-src/client/channels/shared/token-channel.js +9 -1
  16. package/plugin-src/client/channels/wecom/api.js +2 -0
  17. package/plugin-src/client/channels/wecom/index.js +9 -1
  18. package/plugin-src/client/channels/weixin/api.js +2 -10
  19. package/plugin-src/client/channels/weixin/index.js +9 -5
  20. package/plugin-src/client/channels/whatsapp/api.js +2 -0
  21. package/plugin-src/client/channels/whatsapp/index.js +9 -1
  22. package/plugin-src/client/i18n.js +31 -25
  23. package/plugin-src/client/index.js +16 -2
  24. package/plugin-src/client/last-message-error.js +17 -0
  25. package/plugin-src/client/styles.js +5 -1
  26. package/plugin-src/host/channels/feishu/rpc.mjs +3 -0
  27. package/src/channels/dingtalk/dingtalk-api.mjs +1 -1
  28. package/src/channels/dingtalk/dingtalk-bridge.mjs +50 -16
  29. package/src/channels/dingtalk/dingtalk-card-stream.mjs +2 -2
  30. package/src/channels/dingtalk/dingtalk-controller.mjs +2 -0
  31. package/src/channels/feishu/bridge.mjs +148 -70
  32. package/src/channels/feishu/feishu-cards.mjs +10 -6
  33. package/src/channels/feishu/feishu-runtime.mjs +0 -1
  34. package/src/channels/feishu/message-utils.mjs +1 -1
  35. package/src/channels/feishu/multi-bot-controller.mjs +3 -17
  36. package/src/channels/feishu/repair-manager.mjs +7 -2
  37. package/src/channels/qq/qq-bridge.mjs +84 -28
  38. package/src/channels/qq/qq-controller.mjs +2 -0
  39. package/src/channels/shared/control-command.mjs +11 -1
  40. package/src/channels/shared/harness-client.mjs +40 -4
  41. package/src/channels/shared/i18n-en/feishu.mjs +27 -25
  42. package/src/channels/shared/i18n-en/shared-a.mjs +78 -0
  43. package/src/channels/shared/i18n-en/shared-b.mjs +1 -0
  44. package/src/channels/shared/i18n-en/telegram.mjs +1 -0
  45. package/src/channels/shared/message-failure.mjs +244 -0
  46. package/src/channels/shared/semantic/artifact-delivery.mjs +9 -2
  47. package/src/channels/shared/text-harness-bridge.mjs +66 -60
  48. package/src/channels/shared/token-bot-controller.mjs +2 -0
  49. package/src/channels/slack/slack-controller.mjs +2 -0
  50. package/src/channels/telegram/telegram-runtime.mjs +1 -0
  51. package/src/channels/wecom/wecom-bridge.mjs +50 -15
  52. package/src/channels/wecom/wecom-controller.mjs +2 -0
  53. package/src/channels/weixin/weixin-api.mjs +47 -0
  54. package/src/channels/weixin/weixin-bridge.mjs +262 -43
  55. package/src/channels/weixin/weixin-controller.mjs +2 -15
  56. package/src/channels/weixin/weixin-runtime.mjs +1 -0
  57. package/src/channels/whatsapp/whatsapp-controller.mjs +2 -0
@@ -1,6 +1,8 @@
1
1
  import { RegistrationManager } from './registration-manager.mjs';
2
2
 
3
3
  export const CARD_ACTION_CALLBACK = 'card.action.trigger';
4
+ export const FEISHU_MESSAGE_READ_SCOPE = 'im:message:readonly';
5
+ export const FEISHU_RESOURCE_SCOPE = 'im:resource';
4
6
  export const CALLBACK_REPAIR_OPERATION = 'callback_repair';
5
7
 
6
8
  function accountsDomain(domain) {
@@ -71,8 +73,10 @@ export function assertCallbackRepairUrl(value, expectedAppId, domain = 'feishu')
71
73
  /**
72
74
  * One targeted update attempt for an existing Feishu app. It intentionally
73
75
  * shares RegistrationManager's polling/state implementation while fixing the
74
- * update manifest in one place so callers cannot accidentally add scopes,
75
- * events, presets, or createOnly.
76
+ * update manifest in one place so callers can add only the card callback, the
77
+ * message-read scope needed to download user-sent media, and the resource
78
+ * scope needed to upload bot-sent images/files, without adding unrelated
79
+ * scopes, events, presets, or createOnly.
76
80
  */
77
81
  export class CallbackRepairManager {
78
82
  #manager;
@@ -106,6 +110,7 @@ export class CallbackRepairManager {
106
110
  appId: this.#appId,
107
111
  addons: {
108
112
  preset: false,
113
+ scopes: { tenant: [FEISHU_MESSAGE_READ_SCOPE, FEISHU_RESOURCE_SCOPE] },
109
114
  callbacks: { items: [CARD_ACTION_CALLBACK] },
110
115
  },
111
116
  });
@@ -29,6 +29,7 @@ import {
29
29
  import {
30
30
  fetchImageBuffer,
31
31
  hasInboundImages,
32
+ imagePromptDiagnostic,
32
33
  imagePromptUserMessage,
33
34
  promptContentForMessage,
34
35
  } from '../shared/image-prompt.mjs';
@@ -45,6 +46,12 @@ import {
45
46
  createDeliveryReceipt,
46
47
  providerMessageIdsFor,
47
48
  } from '../shared/semantic/delivery.mjs';
49
+ import {
50
+ channelDeliveryFailure,
51
+ clearLastMessageFailure,
52
+ messageFailureText,
53
+ setLastMessageFailure,
54
+ } from '../shared/message-failure.mjs';
48
55
  import { sendMarkdownReply } from './markdown-reply.mjs';
49
56
  import { t } from '../shared/i18n.mjs';
50
57
 
@@ -90,6 +97,7 @@ function helpText() {
90
97
  t('/send 提交当前批次'),
91
98
  t('/cancel 取消当前批次'),
92
99
  t('/status 检查连接状态'),
100
+ t('/version 查看插件版本'),
93
101
  t('/help 显示本帮助'),
94
102
  ].join('\n');
95
103
  }
@@ -215,9 +223,15 @@ function answerTextForDelivery(answer, artifacts) {
215
223
  }
216
224
 
217
225
  function qqArtifactError(error, { dispatched = false } = {}) {
218
- if (error?.code?.startsWith?.('artifact-') || error?.name === 'UploadDailyLimitExceededError') {
226
+ if (error?.code?.startsWith?.('artifact-')) {
219
227
  return error;
220
228
  }
229
+ if (error?.name === 'UploadDailyLimitExceededError') {
230
+ const wrapped = new Error('QQ daily file upload limit exceeded', { cause: error });
231
+ wrapped.name = error.name;
232
+ wrapped.code = 'artifact-rate-limited';
233
+ return wrapped;
234
+ }
221
235
  const status = Number(error?.httpStatus);
222
236
  const wrapped = new Error('QQ file delivery failed', { cause: error });
223
237
  if (status === 401 || status === 403) wrapped.code = 'artifact-permission-required';
@@ -340,6 +354,7 @@ export function createQqBridgeStatus() {
340
354
  lastReplyAt: null,
341
355
  lastRejectedAt: null,
342
356
  lastError: null,
357
+ lastMessageError: null,
343
358
  };
344
359
  }
345
360
 
@@ -469,8 +484,12 @@ export class QqHarnessBridge {
469
484
  ).catch((error) => {
470
485
  if (error?.code === 'turn-stopped' || this.#signal?.aborted) return;
471
486
  this.#status.lastError = error?.message ?? String(error);
472
- this.#logger.error?.('[dsh-im:qq] failed to process a command:', error);
473
- return this.#bot.sendText(message.replyTarget, t('消息处理失败,请稍后重试。'))
487
+ const failure = setLastMessageFailure(this.#status, error);
488
+ this.#logger.error?.(
489
+ `[dsh-im:qq] failed to process a command [${failure.referenceId}]:`,
490
+ error,
491
+ );
492
+ return this.#bot.sendText(message.replyTarget, messageFailureText(failure))
474
493
  .catch(() => undefined);
475
494
  }).finally(() => {
476
495
  this.#acceptedMessageIds.delete(messageId);
@@ -613,8 +632,12 @@ export class QqHarnessBridge {
613
632
  }).catch(async (error) => {
614
633
  if (this.#signal?.aborted) return;
615
634
  this.#status.lastError = error?.message ?? String(error);
616
- this.#logger.error?.('[dsh-im:qq] failed to process a batch input message:', error);
617
- await this.#bot.sendText(message.replyTarget, t('消息处理失败,请稍后重试。'))
635
+ const failure = setLastMessageFailure(this.#status, error);
636
+ this.#logger.error?.(
637
+ `[dsh-im:qq] failed to process a batch input message [${failure.referenceId}]:`,
638
+ error,
639
+ );
640
+ await this.#bot.sendText(message.replyTarget, messageFailureText(failure))
618
641
  .catch(() => undefined);
619
642
  }).finally(() => {
620
643
  this.#acceptedMessageIds.delete(messageId);
@@ -626,7 +649,7 @@ export class QqHarnessBridge {
626
649
 
627
650
  async #deliverArtifacts(target, replyTo, artifacts = [], baseReceipt = null) {
628
651
  if (artifacts.length === 0) {
629
- return { receipt: baseReceipt, failureNoticeVisible: false };
652
+ return { receipt: baseReceipt, failureNoticeVisible: false, artifactSendErrors: 0 };
630
653
  }
631
654
  const delivery = await deliverOutboundArtifacts({
632
655
  artifacts,
@@ -644,9 +667,13 @@ export class QqHarnessBridge {
644
667
  signal: this.#signal,
645
668
  timeoutMs: this.#fileUploadTimeoutMs,
646
669
  }),
647
- sendFailureNotice: (artifact, error) => this.#bot.sendText(
670
+ onFailure: (artifact, error) => setLastMessageFailure(this.#status, error, {
671
+ userMessage: artifactFailureText(artifact?.fileName, error),
672
+ reason: error?.code,
673
+ }),
674
+ sendFailureNotice: (_artifact, _error, failure) => this.#bot.sendText(
648
675
  target,
649
- artifactFailureText(artifact?.fileName, error),
676
+ messageFailureText(failure),
650
677
  ),
651
678
  logger: this.#logger,
652
679
  });
@@ -657,6 +684,7 @@ export class QqHarnessBridge {
657
684
  return {
658
685
  receipt: delivery.receipt,
659
686
  failureNoticeVisible: delivery.failureNoticeVisible,
687
+ artifactSendErrors: delivery.artifactSendErrors,
660
688
  };
661
689
  }
662
690
 
@@ -675,6 +703,12 @@ export class QqHarnessBridge {
675
703
  this.#status.messagesReceived += 1;
676
704
  this.#status.lastMessageAt = new Date().toISOString();
677
705
  }
706
+ let messageRecorded = alreadyRecorded;
707
+ const markMessageSeen = async () => {
708
+ if (messageRecorded) return;
709
+ await this.#state.markSeen(messageId);
710
+ messageRecorded = true;
711
+ };
678
712
  if (this.#ownerUserOpenid !== '*' && sender !== this.#ownerUserOpenid) {
679
713
  this.#status.messagesRejected += 1;
680
714
  this.#status.lastRejectedAt = new Date().toISOString();
@@ -693,25 +727,25 @@ export class QqHarnessBridge {
693
727
  try {
694
728
  if (!text && !hasImages && !hasFiles) {
695
729
  await this.#bot.sendText(target, t('目前支持文字、图片和文件消息。'));
696
- await this.#state.markSeen(messageId);
730
+ await markMessageSeen();
697
731
  return;
698
732
  }
699
733
  const command = text.toLowerCase();
700
734
  if (!hasImages && !hasFiles && command === '/help') {
701
735
  await this.#bot.sendText(target, helpText());
702
- await this.#state.markSeen(messageId);
736
+ await markMessageSeen();
703
737
  return;
704
738
  }
705
739
  if (!hasImages && !hasFiles && command === '/status') {
706
740
  await this.#harness.ensureRunning({ signal: this.#signal });
707
741
  await this.#bot.sendText(target, t('QQ 机器人与 DeepSeek Harness 连接正常。'));
708
- await this.#state.markSeen(messageId);
742
+ await markMessageSeen();
709
743
  return;
710
744
  }
711
745
  if (!hasImages && !hasFiles && command === '/new') {
712
746
  await this.#state.clearSession(key);
713
747
  await this.#bot.sendText(target, t('已开启新会话。请发送你的问题。'));
714
- await this.#state.markSeen(messageId);
748
+ await markMessageSeen();
715
749
  return;
716
750
  }
717
751
  const workspaceCommand = hasImages || hasFiles
@@ -721,7 +755,7 @@ export class QqHarnessBridge {
721
755
  for (const reply of workspaceCommand.messages ?? [workspaceCommand.message]) {
722
756
  await this.#bot.sendText(target, reply);
723
757
  }
724
- await this.#state.markSeen(messageId);
758
+ await markMessageSeen();
725
759
  return;
726
760
  }
727
761
  const compactCommand = hasImages || hasFiles
@@ -735,7 +769,7 @@ export class QqHarnessBridge {
735
769
  );
736
770
  if (compactCommand) {
737
771
  await this.#bot.sendText(target, compactCommand.message);
738
- await this.#state.markSeen(messageId);
772
+ await markMessageSeen();
739
773
  return;
740
774
  }
741
775
 
@@ -756,6 +790,9 @@ export class QqHarnessBridge {
756
790
  let answer;
757
791
  let artifacts = [];
758
792
  try {
793
+ // Persist consumption before handing the prompt to Harness. Provider
794
+ // redelivery after a failed error notice must never execute it twice.
795
+ await markMessageSeen();
759
796
  ({ answer, artifacts = [] } = await askInWorkspaceSession({
760
797
  harness: this.#harness,
761
798
  state: this.#state,
@@ -770,10 +807,13 @@ export class QqHarnessBridge {
770
807
  progressMode: 'all',
771
808
  onUpdate: (update) => {
772
809
  if (update.error) {
773
- const label = nonEmptyString(update.toolName)
774
- ? `Tool call ${update.toolName}` : 'Tool call';
775
- const text = `${label}\nError: ${update.error}`;
776
- toolErrors.push(text);
810
+ const name = (nonEmptyString(update.toolName) ?? t('工具'))
811
+ .replace(/[\r\n]+/gu, ' ')
812
+ .slice(0, 80);
813
+ toolErrors.push(t(
814
+ '工具调用「{name}」未成功,请检查工具配置或稍后重试。',
815
+ { name },
816
+ ));
777
817
  }
778
818
  },
779
819
  onInteraction: (interaction) => this.#handleInteraction(interaction, {
@@ -835,7 +875,7 @@ export class QqHarnessBridge {
835
875
  });
836
876
  }
837
877
  } catch (error) {
838
- textSendError = error;
878
+ textSendError = channelDeliveryFailure(error);
839
879
  this.#logger.warn?.('[dsh-im:qq] final text delivery failed; continuing with result files:', error);
840
880
  }
841
881
  const delivery = await this.#deliverArtifacts(target, messageId, artifacts, textReceipt);
@@ -845,10 +885,15 @@ export class QqHarnessBridge {
845
885
  if (textSendError && !artifactDispatched && !delivery.failureNoticeVisible) {
846
886
  throw textSendError;
847
887
  }
848
- await this.#state.markSeen(messageId);
888
+ if (textSendError && delivery.artifactSendErrors === 0) {
889
+ setLastMessageFailure(this.#status, textSendError);
890
+ }
849
891
  this.#status.messagesReplied += 1;
850
892
  this.#status.lastReplyAt = new Date().toISOString();
851
893
  this.#status.lastError = null;
894
+ if (!textSendError && delivery.artifactSendErrors === 0) {
895
+ clearLastMessageFailure(this.#status);
896
+ }
852
897
  return delivery.receipt;
853
898
  } catch (error) {
854
899
  let batchFailureMessage = null;
@@ -871,7 +916,7 @@ export class QqHarnessBridge {
871
916
  } catch (sendError) {
872
917
  this.#logger.warn?.('[dsh-im:qq] unable to announce a stopped QQ turn:', sendError);
873
918
  }
874
- await this.#state.markSeen(messageId);
919
+ await markMessageSeen();
875
920
  return;
876
921
  }
877
922
  try {
@@ -881,16 +926,23 @@ export class QqHarnessBridge {
881
926
  }
882
927
  if (this.#signal?.aborted) return;
883
928
  this.#status.lastError = error?.message ?? String(error);
884
- this.#logger.error?.('[dsh-im:qq] failed to process an inbound message:', error);
929
+ const userMessage = inboundFileUserMessage(error)
930
+ ?? imagePromptUserMessage(error);
931
+ const failure = setLastMessageFailure(this.#status, error, {
932
+ userMessage,
933
+ reason: imagePromptDiagnostic(error)?.reason,
934
+ });
935
+ this.#logger.error?.(
936
+ `[dsh-im:qq] failed to process an inbound message [${failure.referenceId}]:`,
937
+ error,
938
+ );
885
939
  try {
886
- const errorMessage = inboundFileUserMessage(error)
887
- ?? imagePromptUserMessage(error)
888
- ?? t('消息处理失败,请稍后重试。');
940
+ const errorMessage = messageFailureText(failure);
889
941
  await this.#bot.sendText(
890
942
  target,
891
943
  batchFailureMessage ? `${errorMessage}\n\n${batchFailureMessage}` : errorMessage,
892
944
  );
893
- await this.#state.markSeen(messageId);
945
+ await markMessageSeen();
894
946
  } catch (sendError) {
895
947
  this.#logger.error?.('[dsh-im:qq] failed to send the safe error reply:', sendError);
896
948
  }
@@ -1165,11 +1217,15 @@ export class QqHarnessBridge {
1165
1217
  async #handleInteractionFailure(message, messageId, error) {
1166
1218
  if (this.#signal?.aborted) return;
1167
1219
  this.#status.lastError = error?.message ?? String(error);
1168
- this.#logger.error?.('[dsh-im:qq] failed to process an interaction reply:', error);
1220
+ const failure = setLastMessageFailure(this.#status, error);
1221
+ this.#logger.error?.(
1222
+ `[dsh-im:qq] failed to process an interaction reply [${failure.referenceId}]:`,
1223
+ error,
1224
+ );
1169
1225
  if (!this.#state.hasSeen(messageId)) {
1170
1226
  await this.#state.markSeen(messageId).catch(() => undefined);
1171
1227
  }
1172
- await this.#bot.sendText(message.replyTarget, t('消息处理失败,请稍后重试。'))
1228
+ await this.#bot.sendText(message.replyTarget, messageFailureText(failure))
1173
1229
  .catch(() => undefined);
1174
1230
  }
1175
1231
  }
@@ -2,6 +2,7 @@ import { randomUUID } from 'node:crypto';
2
2
 
3
3
  import { connectionTestMessage } from '../shared/connection-test.mjs';
4
4
  import { t } from '../shared/i18n.mjs';
5
+ import { publicMessageFailure } from '../shared/message-failure.mjs';
5
6
  import { deriveQqBotIdentity, maskQqAppId } from './config-store.mjs';
6
7
 
7
8
  const ACTIVE_ATTEMPT_STATES = new Set(['starting', 'pending', 'refreshing', 'connecting']);
@@ -319,6 +320,7 @@ export class QqController {
319
320
  messagesReceived: runtimeStatus?.messagesReceived ?? 0,
320
321
  messagesReplied: runtimeStatus?.messagesReplied ?? 0,
321
322
  },
323
+ lastMessageError: publicMessageFailure(runtimeStatus?.lastMessageError),
322
324
  error: structuredClone(this.#errors.get(config.botId) ?? null),
323
325
  };
324
326
  });
@@ -1,8 +1,11 @@
1
1
  import { t } from './i18n.mjs';
2
+ import manifest from '../../../package.json' with { type: 'json' };
2
3
 
3
- const CONTROL_COMMAND = /^\/(?:stop|steer)(?=$|\s)/iu;
4
+ const CONTROL_COMMAND = /^\/(?:stop|steer|version)(?=$|\s)/iu;
4
5
  const STOP_COMMAND = /^\/stop(?=$|\s)/iu;
6
+ const VERSION_COMMAND = /^\/version(?=$|\s)/iu;
5
7
  const STOP_USAGE = '用法:/stop(不带参数)';
8
+ const VERSION_USAGE = '用法:/version(不带参数)';
6
9
  const STEER_USAGE = '用法:/steer <补充指令>';
7
10
  const TEXT_ONLY = '控制命令仅支持纯文字,请移除图片后重试。';
8
11
 
@@ -41,9 +44,16 @@ export async function runControlCommand(text, harness, state, key, {
41
44
  if (!isControlCommand(text)) return null;
42
45
  const command = text.trim();
43
46
  const stop = STOP_COMMAND.test(command);
47
+ const version = VERSION_COMMAND.test(command);
44
48
 
45
49
  if (hasImages) return commandResult(t(TEXT_ONLY));
46
50
 
51
+ if (version) {
52
+ return /^\/version$/iu.test(command)
53
+ ? commandResult(`dsh-im v${manifest.version}`)
54
+ : commandResult(t(VERSION_USAGE));
55
+ }
56
+
47
57
  if (stop) {
48
58
  if (!/^\/stop$/iu.test(command)) return commandResult(t(STOP_USAGE));
49
59
  const session = boundSession(harness, state, key);
@@ -532,6 +532,41 @@ export class HarnessInteractionError extends Error {
532
532
  }
533
533
  }
534
534
 
535
+ export class HarnessTurnError extends Error {
536
+ constructor(code, { reason, providerCode } = {}) {
537
+ super(`Harness turn failed (${code})`);
538
+ this.name = 'HarnessTurnError';
539
+ this.code = code;
540
+ this.promptAccepted = true;
541
+ if (reason && typeof reason === 'object') this.reason = reason;
542
+ if (typeof providerCode === 'string' && providerCode) this.providerCode = providerCode;
543
+ }
544
+ }
545
+
546
+ function harnessTurnError(reason) {
547
+ const kind = nonEmptyText(reason?.kind) ?? nonEmptyText(reason);
548
+ if (kind === 'error') {
549
+ const failure = reason?.error ?? reason?.failure;
550
+ return new HarnessTurnError('harness-turn-failed', {
551
+ reason,
552
+ providerCode: nonEmptyText(failure?.code) ?? undefined,
553
+ });
554
+ }
555
+ if (kind === 'max-tokens') return new HarnessTurnError('model-max-tokens', { reason });
556
+ if (kind === 'blocked') return new HarnessTurnError('turn-blocked', { reason });
557
+ if (['interrupted', 'stopped', 'cancelled', 'canceled'].includes(kind)) {
558
+ return new HarnessTurnError('turn-interrupted', { reason });
559
+ }
560
+ if (kind === 'aborted') return new HarnessTurnError('turn-aborted', { reason });
561
+ if (kind === 'completed') return new HarnessTurnError('model-empty-response', { reason });
562
+ return new HarnessTurnError('harness-turn-failed', { reason });
563
+ }
564
+
565
+ function harnessTurnSucceeded(reason) {
566
+ if (reason === null || reason === undefined) return true;
567
+ return (nonEmptyText(reason?.kind) ?? nonEmptyText(reason)) === 'completed';
568
+ }
569
+
535
570
  export class HarnessClient {
536
571
  #baseUrl;
537
572
  #workspace;
@@ -1282,6 +1317,9 @@ export class HarnessClient {
1282
1317
  }
1283
1318
  if (!tracker.finished) continue;
1284
1319
  turnFinished = true;
1320
+ if (!ownership?.stopRequested && !harnessTurnSucceeded(tracker.reason)) {
1321
+ throw harnessTurnError(tracker.reason);
1322
+ }
1285
1323
  // An accepted /stop revokes attachment delivery even when Harness
1286
1324
  // preserved a useful partial text answer for the existing UX.
1287
1325
  const artifactCount = ownership?.stopRequested
@@ -1292,11 +1330,9 @@ export class HarnessClient {
1292
1330
  }
1293
1331
  if (artifactCount > 0) return '';
1294
1332
  if (ownership?.stopRequested) throw turnStoppedError();
1295
- throw new Error(
1296
- `Harness turn ended without a text reply${tracker.reason ? ` (${JSON.stringify(tracker.reason)})` : ''}`,
1297
- );
1333
+ throw harnessTurnError(tracker.reason);
1298
1334
  }
1299
- throw new Error(`Harness reply timed out after ${Math.round(timeoutMs / 1_000)} seconds`);
1335
+ throw new HarnessTurnError('harness-reply-timeout');
1300
1336
  } catch (error) {
1301
1337
  // Once cancellation was accepted, transport/poll failures and timeouts
1302
1338
  // describe the convergence of that stop, not an unrelated ask failure.
@@ -3,7 +3,7 @@ export default {
3
3
  // feishu/bridge.mjs — welcome / help
4
4
  '北汇星河 AIOS 已连接 DeepSeek Harness。':
5
5
  'BeiHui XingHe AIOS is connected to DeepSeek Harness.',
6
- '/repair 修复卡片按钮回调': '/repair Repair the card-button callback',
6
+ '/repair 补全飞书权限与卡片回调': '/repair Complete Feishu permissions and the card callback',
7
7
  '/m(或 /menu) 打开交互卡片菜单': '/m (or /menu) Open the interactive card menu',
8
8
  '/watch [Session ID 或序号] 关注会话,任务完成自动推送':
9
9
  '/watch [Session ID or index] Watch a session; completion is pushed automatically',
@@ -18,8 +18,8 @@ export default {
18
18
  '机器人正在移除或已重新接入,无法操作原会话的工作区。':
19
19
  'The bot is being removed or has been reconnected; the original session’s workspace cannot be changed.',
20
20
  '操作失败,请稍后重试。': 'The operation failed. Please try again later.',
21
- '结果文件「{name}」已生成,但机器人缺少飞书文件上传权限。请为应用添加 im:resource 并完成必要审批后重试。':
22
- 'The result file "{name}" was generated, but the bot lacks Feishu file-upload permission. Add the im:resource scope to the app, complete the required approval, and try again.',
21
+ '结果文件「{name}」已生成,但机器人缺少飞书文件上传权限 im:resource。请私聊机器人执行 /repair 命令,或者在插件页面点击“补全权限”按钮并扫码。完成飞书要求的发布审批后重试。':
22
+ 'The result file "{name}" was generated, but the bot lacks the Feishu file-upload scope im:resource. Run /repair in a direct chat with the bot, or click the “Complete permissions” button on the plugin page and scan the QR code. Complete any publishing approval Feishu requires, then try again.',
23
23
  '结果文件「{name}」超过飞书 30 MB 上限,未发送。':
24
24
  'The result file "{name}" exceeds the Feishu 30 MB limit and was not sent.',
25
25
  '结果文件「{name}」为空,飞书不允许发送空文件。':
@@ -41,20 +41,20 @@ export default {
41
41
  // feishu/bridge.mjs — repair flow
42
42
  '为避免授权链接暴露,请私聊机器人发送 /repair。':
43
43
  'To keep the authorization link private, send /repair to the bot in a direct message.',
44
- '当前机器人没有可验证的接入者身份,不能从聊天发起修复;请先在插件页设置管理员。':
45
- 'This bot has no verifiable owner identity, so repair cannot be started from chat. Set an administrator on the plugin page first.',
46
- '此操作只能由机器人接入者在私聊中发起,未进行任何修改。':
47
- 'This action can only be started by the bot owner in a direct message. Nothing was changed.',
44
+ '无法识别当前发送者,未发起修复。':
45
+ 'The current sender could not be identified, so repair was not started.',
48
46
  '当前 Host 版本暂不支持聊天内修复,请先更新插件。':
49
47
  'The current Host version does not support in-chat repair. Update the plugin first.',
50
48
  '用法:/repair、/repair qr、/repair status、/repair cancel 或 /repair verify':
51
49
  'Usage: /repair, /repair qr, /repair status, /repair cancel, or /repair verify',
52
50
  '当前 Runtime 没有可恢复的修复任务记录(机器人可能刚完成密钥更新并重启)。本命令不会启动新的授权;请查看机器人发送的验证结果,确认上一次任务已结束后再发送 /repair。':
53
51
  'The current Runtime has no recoverable repair attempt (the bot may have just rotated its secret and restarted). This command starts no new authorization. Check the verification result the bot sent, then send /repair after the previous attempt has finished.',
54
- '另一位管理员正在修复该机器人,本次不会显示其授权信息。':
55
- 'Another administrator is repairing this bot; its authorization info will not be shown this time.',
52
+ '另一位用户正在修复该机器人,本次不会显示其授权信息。':
53
+ 'Another user is repairing this bot; its authorization info will not be shown this time.',
56
54
  '暂时无法取消修复任务,请稍后重试。':
57
55
  'Could not cancel the repair task right now. Please try again later.',
56
+ '暂时无法取消旧修复任务,未生成新链接;请稍后重试。':
57
+ 'Could not cancel the previous repair attempt, so no new link was generated. Please try again later.',
58
58
  '暂时无法查询修复状态,请稍后重试。':
59
59
  'Could not check the repair status right now. Please try again later.',
60
60
  '修复流程暂时失败,现有机器人连接不受影响;请稍后发送 /repair 重试。':
@@ -69,10 +69,11 @@ export default {
69
69
  'The repair status query was interrupted; the existing bot connection is unaffected. Send /repair status to retry.',
70
70
  '链接为短期有效': 'The link is valid for a short time.',
71
71
  '链接约 {minutes} 分钟后过期': 'The link expires in about {minutes} minutes',
72
- '已有一个修复任务在等待授权。': 'A repair task is already waiting for authorization.',
73
- '🔧 准备修复卡片按钮。': '🔧 Preparing to repair the card buttons.',
74
- '本次只会增量添加 card.action.trigger。请核对确认页只显示这一项;若出现其他权限或事件,请取消。':
75
- 'Only card.action.trigger will be added. Check that the confirmation page shows only this item; cancel if any other permission or event appears.',
72
+ '旧授权链接已作废,已生成新的修复链接。':
73
+ 'The previous authorization link was invalidated and a new repair link was generated.',
74
+ '🔧 准备补全权限与回调。': '🔧 Preparing to complete permissions and the callback.',
75
+ '本次最多增量添加三项:卡片回调 card.action.trigger;飞书显示为“获取单聊、群组消息”的租户权限 im:message:readonly(用于读取用户消息中的图片或文件);以及 im:resource(用于上传机器人发送的图片或文件)。确认页只会显示当前缺少的项;若出现上述范围之外的配置,请取消。':
76
+ 'This may incrementally add up to three items: the card callback card.action.trigger; the tenant scope im:message:readonly, shown by Feishu as “Read direct and group messages” and used to read images or files in user messages; and im:resource, used to upload images or files sent by the bot. The confirmation page shows only items the app is currently missing; cancel if anything outside this scope appears.',
76
77
  '当前设备直接打开:': 'Open directly on this device:',
77
78
  '若要用另一台设备扫码,发送 /repair qr。{expiry}。':
78
79
  'To scan with another device, send /repair qr. {expiry}.',
@@ -199,8 +200,8 @@ export default {
199
200
  '切换归档显示': 'Toggle archived sessions',
200
201
  '📊 状态': '📊 Status',
201
202
  '📖 帮助': '📖 Help',
202
- '**数字兜底**\n**1**工作区列表 · **2**新会话 · **3**会话列表 · **4**状态\n**5**🔧修复 · **6**帮助':
203
- '**Number fallback**\n**1** Workspace list · **2** New session · **3** Session list · **4** Status\n**5** 🔧 Repair · **6** Help',
203
+ '**数字兜底**\n**1**工作区列表 · **2**新会话 · **3**会话列表 · **4**状态\n**5**🔧补全权限 · **6**帮助':
204
+ '**Number fallback**\n**1** Workspace list · **2** New session · **3** Session list · **4** Status\n**5** 🔧 Complete permissions · **6** Help',
204
205
  '跟随 Host 默认{default}': 'Follow Host default{default}',
205
206
  '**当前**:{value}': '**Current**: {value}',
206
207
  '**Host 默认**:{value}': '**Host default**: {value}',
@@ -228,6 +229,7 @@ export default {
228
229
  '/new 开启全新会话': '/new Start a new session',
229
230
  '📊 状态 / 压缩': '📊 Status / compact',
230
231
  '/status 连接状态': '/status Connection status',
232
+ '`/version` — 查看插件版本': '`/version` — show the plugin version',
231
233
  '/compact 压缩当前会话上下文': '/compact Compact the current session context',
232
234
  '/archived on/off 会话列表显示/隐藏归档': '/archived on/off Show/hide archived sessions',
233
235
  '👁 关注': '👁 Watches',
@@ -241,10 +243,10 @@ export default {
241
243
  '/steer 指令 给 Agent 补充指令': '/steer INSTRUCTION Steer the Agent',
242
244
  '**📋 卡片功能**\n\n1. 会话下拉 — 切换当前绑定会话\n2. 工作区下拉 — 切换工作区\n3. 🤖 预设下拉 — 切换 Agent 预设\n4. 🧠 模型下拉 — 切换模型\n5. 🆕 新会话 — 开启全新会话\n6. 📋 会话/关注 — 查看/绑定会话,管理关注\n7. ⏹ 停止 — 停止当前任务\n8. 📐 压缩 — 压缩当前会话上下文\n9. 补充指令 — 给 Agent 发送指令\n10. 🗄 归档切换 — 显示/隐藏归档会话\n11. 📊 状态 — 查看系统连接状态\n12. 📖 帮助 — 查看本帮助':
243
245
  '**📋 Card features**\n\n1. Session dropdown — switch the bound session\n2. Workspace dropdown — switch workspace\n3. 🤖 Preset dropdown — switch Agent Preset\n4. 🧠 Model dropdown — switch model\n5. 🆕 New session — start fresh\n6. 📋 Sessions/watches — view or bind sessions and manage watches\n7. ⏹ Stop — stop the current task\n8. 📐 Compact — compact the current session context\n9. Steer task — send an instruction to the Agent\n10. 🗄 Archived toggle — show or hide archived sessions\n11. 📊 Status — view connection status\n12. 📖 Help — view this help',
244
- '**⌨️ 文本命令**\n\n`/m` — 打开菜单卡片\n`/new` — 开启全新会话\n`/session ID` — 绑定已有会话\n`/sessionlist [工作区]` — 列出会话\n`/workspace 路径` — 切换工作区\n`/workspacelist` — 列出工作区\n`/status` — 查看连接状态\n`/compact` — 压缩上下文\n`/stop` — 停止当前任务\n`/steer 指令` — 补充指令\n`/watch ID` — 关注会话\n`/watchlist` — 关注列表\n`/unwatch ID` — 取消关注\n`/archived on/off` — 归档显隐\n`/presetlist` — 列出预设\n`/preset [序号/ID]` — 切换预设\n`/preset --default` — 跟随默认\n`/models` — 列出模型\n`/reasoninglist` 或 `/reasonings` — 按序号列出当前模型可用推理等级\n`/reasoning [序号、等级ID或 --default]` — 查看或切换当前推理等级\n`/model [序号或完整模型ID] [推理等级ID]` — 查看或切换当前会话模型\n`/batch` — 开启批量输入(仅私聊,最多 10 条文字)\n`/send` — 提交当前批次\n`/cancel` — 取消当前批次\n`/repair` — 修复卡片按钮':
245
- '**⌨️ Text commands**\n\n`/m` — open the menu card\n`/new` — start a new session\n`/session ID` — bind an existing session\n`/sessionlist [workspace]` — list sessions\n`/workspace PATH` — switch workspace\n`/workspacelist` — list workspaces\n`/status` — view connection status\n`/compact` — compact context\n`/stop` — stop the current task\n`/steer INSTRUCTION` — steer the task\n`/watch ID` — watch a session\n`/watchlist` — list watched sessions\n`/unwatch ID` — stop watching\n`/archived on/off` — show or hide archived sessions\n`/presetlist` — list presets\n`/preset [index/ID]` — switch preset\n`/preset --default` — follow default\n`/models` — list models\n`/reasoninglist` or `/reasonings` — list reasoning efforts for the current model\n`/reasoning [index, effort ID, or --default]` — show or switch reasoning effort\n`/model [index or full model ID] [reasoning effort ID]` — show or switch the current Session model\n`/batch` — start batch input (direct messages only, up to 10 text messages)\n`/send` — submit the current batch\n`/cancel` — cancel the current batch\n`/repair` — repair card buttons',
246
- '**💡 数字兜底**\n回复数字快速操作:\n**1**工作区列表 · **2**新会话 · **3**会话/关注\n**4**状态 · **5**修复 · **6**帮助':
247
- '**💡 Number fallback**\nReply with a number for a quick action:\n**1** Workspace list · **2** New session · **3** Sessions/watches\n**4** Status · **5** Repair · **6** Help',
246
+ '**⌨️ 文本命令**\n\n`/m` — 打开菜单卡片\n`/new` — 开启全新会话\n`/session ID` — 绑定已有会话\n`/sessionlist [工作区]` — 列出会话\n`/workspace 路径` — 切换工作区\n`/workspacelist` — 列出工作区\n`/status` — 查看连接状态\n`/compact` — 压缩上下文\n`/stop` — 停止当前任务\n`/steer 指令` — 补充指令\n`/watch ID` — 关注会话\n`/watchlist` — 关注列表\n`/unwatch ID` — 取消关注\n`/archived on/off` — 归档显隐\n`/presetlist` — 列出预设\n`/preset [序号/ID]` — 切换预设\n`/preset --default` — 跟随默认\n`/models` — 列出模型\n`/reasoninglist` 或 `/reasonings` — 按序号列出当前模型可用推理等级\n`/reasoning [序号、等级ID或 --default]` — 查看或切换当前推理等级\n`/model [序号或完整模型ID] [推理等级ID]` — 查看或切换当前会话模型\n`/batch` — 开启批量输入(仅私聊,最多 10 条文字)\n`/send` — 提交当前批次\n`/cancel` — 取消当前批次\n`/repair` — 补全飞书权限与卡片回调':
247
+ '**⌨️ Text commands**\n\n`/m` — open the menu card\n`/new` — start a new session\n`/session ID` — bind an existing session\n`/sessionlist [workspace]` — list sessions\n`/workspace PATH` — switch workspace\n`/workspacelist` — list workspaces\n`/status` — view connection status\n`/compact` — compact context\n`/stop` — stop the current task\n`/steer INSTRUCTION` — steer the task\n`/watch ID` — watch a session\n`/watchlist` — list watched sessions\n`/unwatch ID` — stop watching\n`/archived on/off` — show or hide archived sessions\n`/presetlist` — list presets\n`/preset [index/ID]` — switch preset\n`/preset --default` — follow default\n`/models` — list models\n`/reasoninglist` or `/reasonings` — list reasoning efforts for the current model\n`/reasoning [index, effort ID, or --default]` — show or switch reasoning effort\n`/model [index or full model ID] [reasoning effort ID]` — show or switch the current Session model\n`/batch` — start batch input (direct messages only, up to 10 text messages)\n`/send` — submit the current batch\n`/cancel` — cancel the current batch\n`/repair` — complete Feishu permissions and the card callback',
248
+ '**💡 数字兜底**\n回复数字快速操作:\n**1**工作区列表 · **2**新会话 · **3**会话/关注\n**4**状态 · **5**补全权限 · **6**帮助':
249
+ '**💡 Number fallback**\nReply with a number for a quick action:\n**1** Workspace list · **2** New session · **3** Sessions/watches\n**4** Status · **5** Complete permissions · **6** Help',
248
250
  '从下方下拉选择补充指令;最后一项可自定义输入。':
249
251
  'Choose an instruction below; the last option lets you enter a custom one.',
250
252
  '当前没有绑定会话,请先绑定会话再补充指令。':
@@ -262,8 +264,8 @@ export default {
262
264
  '3 · 新会话': '3 · New session',
263
265
  '4 · 状态': '4 · Status',
264
266
  '5 · 帮助': '5 · Help',
265
- '**6 · 修复卡片按钮**(请直接回复数字 **6**)':
266
- '**6 · Repair card buttons** (reply with the number **6**)',
267
+ '**6 · 补全权限**(请直接回复数字 **6**)':
268
+ '**6 · Complete permissions** (reply with the number **6**)',
267
269
  '7 · 关注列表': '7 · Watch list',
268
270
  '🧪 验证卡片按钮': '🧪 Verify card buttons',
269
271
  '授权已提交。请点击下方按钮;机器人真实收到回调后才会判定修复成功。':
@@ -290,8 +292,8 @@ export default {
290
292
  '3 · /new 开启新会话': '3 · /new Start a new session',
291
293
  '4 · /status 连接状态': '4 · /status Connection status',
292
294
  '5 · /help 本帮助': '5 · /help This help',
293
- '6 · /repair 修复卡片按钮(请回复数字 6)':
294
- '6 · /repair Repair card buttons (reply with the number 6)',
295
+ '6 · /repair 补全权限与回调(请回复数字 6)':
296
+ '6 · /repair Complete permissions and callback (reply with the number 6)',
295
297
  '7 · /watchlist 关注列表': '7 · /watchlist Watch list',
296
298
  '直接发送文字/图片即继续当前会话。':
297
299
  'Send text or an image directly to continue the current session.',
@@ -336,8 +338,8 @@ export default {
336
338
  '飞书机器人': 'Feishu bot',
337
339
 
338
340
  // feishu/message-utils.mjs
339
- '飞书机器人缺少图片读取权限。请在飞书开放平台为该应用添加 im:message:readonly,发布新版本并完成必要的管理员审批后,再重新发送图片。':
340
- 'The Feishu bot is missing image-read permission. Add im:message:readonly to the app in Feishu Open Platform, publish a new version, complete the required admin approval, then resend the image.',
341
+ '飞书机器人缺少图片读取权限 im:message:readonly(飞书显示为“获取单聊、群组消息”)。请私聊机器人执行 /repair 命令,或者在插件页面点击“补全权限”按钮并扫码。按飞书提示发布新版本、完成必要审批后,再重新发送图片。':
342
+ 'The Feishu bot is missing the image-read scope im:message:readonly, shown by Feishu as “Read direct and group messages.” Run /repair in a direct chat with the bot, or click the “Complete permissions” button on the plugin page and scan the QR code. Publish a new version and complete any approval requested by Feishu, then resend the image.',
341
343
 
342
344
  // feishu/feishu-runtime.mjs — callback probe notices
343
345
  '✅ 修复完成:已实测收到 card.action.trigger,菜单按钮现在可用。':