@xmanrui/dsh-im 5.7.0 → 5.8.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 (29) hide show
  1. package/lib/client.js +342 -159
  2. package/lib/index.js +323 -321
  3. package/package.json +1 -1
  4. package/plugin-src/client/channels/feishu/api.js +5 -0
  5. package/plugin-src/client/channels/feishu/conversation-directory-settings.js +73 -0
  6. package/plugin-src/client/channels/feishu/index.js +1 -0
  7. package/plugin-src/client/delivery-settings.js +4 -0
  8. package/plugin-src/client/i18n-ru.js +17 -0
  9. package/plugin-src/client/i18n.js +17 -0
  10. package/plugin-src/client/styles.js +6 -0
  11. package/plugin-src/client/workspace-editor.js +6 -5
  12. package/plugin-src/host/channels/feishu/rpc.mjs +25 -0
  13. package/plugin-src/host/channels/shared/workspace-rpc.mjs +2 -0
  14. package/scripts/verify-package.mjs +17 -6
  15. package/src/channels/feishu/bridge.mjs +29 -12
  16. package/src/channels/feishu/message-utils.mjs +1 -0
  17. package/src/channels/shared/bot-workspace-store.mjs +248 -0
  18. package/src/channels/shared/conversation-directory-ensure.mjs +46 -0
  19. package/src/channels/shared/conversation-directory.mjs +29 -0
  20. package/src/channels/shared/harness-client.mjs +72 -2
  21. package/src/channels/shared/i18n-en/diagnostics.mjs +2 -0
  22. package/src/channels/shared/i18n-en/shared-a.mjs +5 -0
  23. package/src/channels/shared/i18n-ru/diagnostics.mjs +2 -0
  24. package/src/channels/shared/i18n-ru/shared-a.mjs +5 -0
  25. package/src/channels/shared/message-failure.mjs +8 -0
  26. package/src/channels/shared/new-command.mjs +7 -0
  27. package/src/channels/shared/semantic/reply-reference.mjs +25 -5
  28. package/src/channels/shared/text-harness-bridge.mjs +3 -2
  29. package/src/channels/shared/workspace-command.mjs +22 -9
@@ -26,6 +26,11 @@ const PROVIDER_FAILURES = Object.freeze({
26
26
  UNSUPPORTED_CONTENT: 'MODEL_CONFIG',
27
27
  });
28
28
 
29
+ // 提交超时(stage=prompt.submit 且 harness-timeout)单列文案:与「已提交、结果
30
+ // 未知」区分,明确「提交请求本身超时、是否送达未知」,避免用户误以为任务已运行。
31
+ const PROMPT_SUBMIT_UNCONFIRMED_MESSAGE =
32
+ '消息提交请求超时,未能确认消息是否已送达 DSH。请稍后到 DSH 查看该会话状态,不要立即重复提交;若持续发生,请将参考号提供给管理员。';
33
+
29
34
  const FAILURE_MESSAGES = Object.freeze({
30
35
  HARNESS_INTERACTION_TIMEOUT:
31
36
  '与 DSH 的交互通道在 30 秒内未就绪,本条消息尚未提交执行。请稍后重试。',
@@ -230,6 +235,9 @@ export function classifyMessageFailure(error, {
230
235
  if (code === 'REQUEST_TIMEOUT' || code === 'NETWORK_ERROR') details.hint = connectionHint(details);
231
236
  if (details.stage || details.submissionState) Object.assign(details, runtimeDiagnosticDetails());
232
237
  let message = FAILURE_MESSAGES[code];
238
+ if (code === 'HARNESS_RESULT_UNCERTAIN' && error?.code === 'harness-timeout' && details.stage === 'prompt.submit') {
239
+ message = PROMPT_SUBMIT_UNCONFIRMED_MESSAGE;
240
+ }
233
241
  if (['INTERNAL_UNKNOWN', 'REQUEST_TIMEOUT', 'NETWORK_ERROR'].includes(code)) {
234
242
  if (details.submissionState === 'not-submitted') {
235
243
  message = code === 'REQUEST_TIMEOUT'
@@ -0,0 +1,7 @@
1
+ import { t } from './i18n.mjs';
2
+
3
+ export async function startNewConversation({ state, harness, key }) {
4
+ const result = await harness.prepareConversationDirectory?.(key, { explicitNew: true });
5
+ await state.clearSession(key);
6
+ return [t('已开启全新 Harness 会话。'), result?.warning ? t(result.warning) : null].filter(Boolean).join('\n');
7
+ }
@@ -1,4 +1,3 @@
1
- import { INJECTED_CONTEXT_TAGS } from '../context-enhancement.mjs';
2
1
  import { promptContentForMessage } from '../image-prompt.mjs';
3
2
 
4
3
  const REPLY_CONTENT_MAX_CODE_POINTS = 8_000;
@@ -80,7 +79,7 @@ function errorUnavailableReason(error) {
80
79
  function mergeDefined(base, loaded) {
81
80
  const merged = { ...base };
82
81
  for (const key of [
83
- 'messageId', 'authorId', 'authorName', 'content', 'attachments', 'unavailableReason',
82
+ 'messageId', 'authorId', 'authorName', 'content', 'attachments', 'files', 'unavailableReason',
84
83
  ]) {
85
84
  if (loaded[key] !== undefined) merged[key] = loaded[key];
86
85
  }
@@ -108,6 +107,7 @@ function normalizeReference(reference) {
108
107
  const authorName = cleanString(reference.authorName, REPLY_AUTHOR_NAME_MAX_CODE_POINTS);
109
108
  const content = cleanString(reference.content, REPLY_CONTENT_MAX_CODE_POINTS, { multiline: true });
110
109
  const { attachments, truncated: attachmentsTruncated } = cleanAttachments(reference.attachments);
110
+ const files = Array.isArray(reference.files) ? reference.files.filter((file) => file && typeof file.load === 'function') : [];
111
111
  let unavailableReason = cleanUnavailableReason(reference.unavailableReason);
112
112
  if (!content.value && attachments.length === 0 && !unavailableReason) {
113
113
  unavailableReason = 'not-delivered';
@@ -120,29 +120,49 @@ function normalizeReference(reference) {
120
120
  ...(authorName.value ? { authorName: authorName.value } : {}),
121
121
  ...(content.value ? { content: content.value } : {}),
122
122
  ...(attachments.length > 0 ? { attachments } : {}),
123
+ ...(files.length > 0 ? { files } : {}),
123
124
  ...(unavailableReason ? { unavailableReason } : {}),
124
125
  ...(truncated ? { truncated: true } : {}),
125
126
  };
126
127
  }
127
128
 
128
129
  function replyBlock(reference) {
129
- const json = JSON.stringify(reference).replace(/[<>&]/gu, (character) => ({
130
+ const { files: _files, ...visibleReference } = reference;
131
+ const json = JSON.stringify(visibleReference).replace(/[<>&]/gu, (character) => ({
130
132
  '<': '\\u003c',
131
133
  '>': '\\u003e',
132
134
  '&': '\\u0026',
133
135
  })[character]);
134
- return `${INJECTED_CONTEXT_TAGS.replyOpen}${json}${INJECTED_CONTEXT_TAGS.replyClose}`;
136
+ return `<dsh_im_reply_to>${json}</dsh_im_reply_to>`;
135
137
  }
136
138
 
137
139
  export function hasReplyReference(message) {
138
140
  return objectReference(message?.replyTo);
139
141
  }
140
142
 
141
- export async function promptContentForInboundMessage(message, { signal, deferImages = false } = {}) {
143
+ export async function promptContentForInboundMessage(
144
+ message,
145
+ { signal, deferImages = false, originalFiles } = {},
146
+ ) {
142
147
  if (!hasReplyReference(message)) {
143
148
  return promptContentForMessage(message, { signal, deferImages });
144
149
  }
145
150
  const reference = normalizeReference(await resolveReference(message.replyTo, signal));
151
+ // A quoted attachment is part of the user's explicit request. Preserve its
152
+ // lazy source on the current message so the normal inbound-file pipeline
153
+ // downloads and stages it alongside files attached to the new message.
154
+ if (Array.isArray(originalFiles)) {
155
+ if (!Array.isArray(message.files)) message.files = [];
156
+ // A workspace retry can rebuild the same quoted prompt. Restore the
157
+ // caller's original attachments before appending the lazy quote files;
158
+ // keep the existing array object so askOptions.files sees the update.
159
+ message.files.length = 0;
160
+ message.files.push(...originalFiles);
161
+ }
162
+ if (Array.isArray(reference.files) && reference.files.length > 0) {
163
+ if (!Array.isArray(message.files)) message.files = [];
164
+ message.files.push(...reference.files);
165
+ }
146
166
  const currentContent = await promptContentForMessage(message, { signal, deferImages });
147
167
  return [{ type: 'text', text: replyBlock(reference) }, ...currentContent];
148
168
  }
@@ -75,6 +75,7 @@ import {
75
75
  } from './message-failure.mjs';
76
76
  import { logDeliveryFailure } from './delivery-failure-log.mjs';
77
77
  import { beginStatusReaction } from './status-reaction.mjs';
78
+ import { startNewConversation } from './new-command.mjs';
78
79
 
79
80
  /** Cap and TTL for the in-memory workspace-picker snapshots behind button presses. */
80
81
  const MAX_WORKSPACE_CARDS = 50;
@@ -1141,7 +1142,7 @@ export class TextHarnessBridge {
1141
1142
  return;
1142
1143
  }
1143
1144
  if (!hasImages && !hasFiles && command === '/new') {
1144
- await this.#state.clearSession(conversationKey);
1145
+ const receipt = await startNewConversation({ state: this.#state, harness: this.#harness, key: conversationKey });
1145
1146
  if (this.#contextHooks?.onSessionCleared) {
1146
1147
  try {
1147
1148
  await this.#contextHooks.onSessionCleared(conversationKey);
@@ -1150,7 +1151,7 @@ export class TextHarnessBridge {
1150
1151
  this.#logger.warn?.(`[dsh-im:${this.#descriptor.key}] failed to reset context anchors after /new:`, error?.message ?? error);
1151
1152
  }
1152
1153
  }
1153
- await this.#bot.sendText(target, t('已开启新会话。请发送你的问题。'));
1154
+ await this.#bot.sendText(target, `${receipt}\n${t('请发送你的问题。')}`);
1154
1155
  return;
1155
1156
  }
1156
1157
  const compactCommand = !hasImages && !hasFiles
@@ -112,18 +112,23 @@ async function selectedWorkspacePath(value) {
112
112
  }
113
113
  }
114
114
 
115
- export async function workspacePathSnapshot(harness, { includeTitles = false, ...options } = {}) {
115
+ export async function workspacePathSnapshot(harness, { includeTitles = false, includeConversationDirectories = false, conversationKey, ...options } = {}) {
116
116
  const withEntries = includeTitles && typeof harness.listWorkspaceEntries === 'function';
117
117
  const listed = await (withEntries ? harness.listWorkspaceEntries(options) : harness.listWorkspaces(options));
118
- const currentValue = typeof harness?.currentWorkspace === 'function'
119
- ? harness.currentWorkspace()
120
- : null;
118
+ const currentValue = typeof harness?.currentConversationWorkspace === 'function'
119
+ && typeof conversationKey === 'string' && conversationKey
120
+ ? harness.currentConversationWorkspace(conversationKey)
121
+ : typeof harness?.currentWorkspace === 'function'
122
+ ? harness.currentWorkspace()
123
+ : null;
121
124
  const current = await existingWorkspacePath(currentValue);
122
125
  const entries = await Promise.all((Array.isArray(listed) ? listed : []).map(async (item) => ({
123
126
  path: await existingWorkspacePath(withEntries ? item?.path : item),
124
127
  title: withEntries ? safeDisplayText(item?.title) : '',
125
128
  })));
126
- const paths = [...new Set([...(current ? [current] : []), ...entries.map((item) => item.path).filter(Boolean)])];
129
+ const directoryPaths = new Set(harness.conversationDirectoryPaths?.() ?? []);
130
+ const paths = [...new Set([...(current ? [current] : []), ...entries.map((item) => item.path).filter(Boolean)])]
131
+ .filter((path) => includeConversationDirectories || path === current || !directoryPaths.has(path));
127
132
  const titles = {};
128
133
  if (includeTitles) {
129
134
  for (const item of entries) {
@@ -162,12 +167,14 @@ export function splitWorkspaceCommandMessage(message) {
162
167
  * channel without an interactive picker keeps exactly what it always showed;
163
168
  * `listing` is the machine-readable half a channel may render as a picker.
164
169
  */
165
- async function workspaceListingCommand(harness) {
170
+ async function workspaceListingCommand(harness, { includeConversationDirectories = false } = {}) {
166
171
  if (typeof harness?.listWorkspaces !== 'function') {
167
172
  return commandResult(t('当前机器人暂不支持列出工作区。'));
168
173
  }
169
174
  try {
170
- const { current, paths, titles } = await workspacePathSnapshot(harness, { includeTitles: true });
175
+ const { current, paths, titles } = await workspacePathSnapshot(harness, {
176
+ includeTitles: true, includeConversationDirectories,
177
+ });
171
178
  if (paths.length === 0) {
172
179
  return commandResult(t('当前 Harness Host 上没有仍然存在的已登记工作区。'));
173
180
  }
@@ -195,8 +202,9 @@ async function workspaceListingCommand(harness) {
195
202
  }
196
203
 
197
204
  async function runWorkspaceListCommand(match, harness) {
198
- if (match[1]?.trim()) return commandResult(t('用法:/workspacelist'));
199
- return workspaceListingCommand(harness);
205
+ const includeConversationDirectories = match[1]?.trim().toLowerCase() === 'all';
206
+ if (match[1]?.trim() && !includeConversationDirectories) return commandResult(t('用法:/workspacelist'));
207
+ return workspaceListingCommand(harness, { includeConversationDirectories });
200
208
  }
201
209
 
202
210
  async function conversationEffectiveWorkspace(harness, conversationKey) {
@@ -475,6 +483,7 @@ async function runConversationWorkspaceCommand(command, harness, conversationKey
475
483
  try {
476
484
  let selected = argument;
477
485
  if (/^\d+$/u.test(argument)) {
486
+ // Match the ordering shown by /workspacelist, /ws and bare /conv.
478
487
  const { paths } = await workspacePathSnapshot(harness);
479
488
  const position = Number(argument);
480
489
  if (!Number.isSafeInteger(position) || position < 1 || position > paths.length) {
@@ -516,6 +525,10 @@ export function workspaceSwitchFailureText(error) {
516
525
 
517
526
  export async function runWorkspaceCommand(text, harness, conversationKey) {
518
527
  if (!isWorkspaceCommand(text)) return null;
528
+ const config = harness.conversationDirectoryConfig?.();
529
+ if (config?.enabled === true && /^(?:\/(?:workspace|ws|conv|conversation|thread))(?:\s|$)/iu.test(text.trim())) {
530
+ return { message: '', messages: [] };
531
+ }
519
532
  const command = text.trim();
520
533
  const threadMatch = THREAD_WORKSPACE_COMMAND.exec(command);
521
534
  if (threadMatch) {