@xmanrui/dsh-im 0.12.0 → 0.14.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 (49) hide show
  1. package/README.en.md +64 -43
  2. package/README.md +66 -45
  3. package/assets/logo-dsh-im-connecting-readme-3x2.png +0 -0
  4. package/assets/logo-dsh-im-connecting-square-v4.png +0 -0
  5. package/assets/logo-plugin-phone.png +0 -0
  6. package/lib/client.js +805 -173
  7. package/lib/index.js +142 -129
  8. package/package.json +4 -3
  9. package/plugin-src/client/build.mjs +1 -6
  10. package/plugin-src/client/channel-logos.js +12 -0
  11. package/plugin-src/client/channels/office/api.js +44 -0
  12. package/plugin-src/client/channels/office/index.js +152 -0
  13. package/plugin-src/client/channels/office/styles.js +50 -0
  14. package/plugin-src/client/channels/shared/token-api.js +5 -1
  15. package/plugin-src/client/channels/shared/token-channel.js +16 -1
  16. package/plugin-src/client/channels/telegram/api.js +17 -2
  17. package/plugin-src/client/channels/telegram/index.js +112 -0
  18. package/plugin-src/client/channels/telegram/styles.js +26 -0
  19. package/plugin-src/client/i18n.js +69 -1
  20. package/plugin-src/client/index.js +22 -12
  21. package/plugin-src/client/styles.js +5 -3
  22. package/plugin-src/host/channels/office/index.mjs +10 -0
  23. package/plugin-src/host/channels/office/production.mjs +45 -0
  24. package/plugin-src/host/channels/office/rpc.mjs +48 -0
  25. package/plugin-src/host/channels/shared/production.mjs +9 -1
  26. package/plugin-src/host/channels/telegram/production.mjs +2 -0
  27. package/plugin-src/host/channels/telegram/rpc.mjs +58 -8
  28. package/plugin-src/host/index.mjs +3 -0
  29. package/scripts/verify-package.mjs +34 -0
  30. package/src/channels/dingtalk/dingtalk-bridge.mjs +3 -2
  31. package/src/channels/discord/discord-api.mjs +1 -1
  32. package/src/channels/feishu/bridge.mjs +3 -2
  33. package/src/channels/office/config-store.mjs +107 -0
  34. package/src/channels/office/office-controller.mjs +167 -0
  35. package/src/channels/office/office-job-executor.mjs +390 -0
  36. package/src/channels/office/office-runtime.mjs +171 -0
  37. package/src/channels/office/office-transport.mjs +170 -0
  38. package/src/channels/office/protocol.mjs +43 -0
  39. package/src/channels/qq/qq-bridge.mjs +3 -2
  40. package/src/channels/shared/model-command.mjs +44 -6
  41. package/src/channels/shared/text-harness-bridge.mjs +3 -2
  42. package/src/channels/shared/token-bot-controller.mjs +28 -0
  43. package/src/channels/shared/token-config-store.mjs +14 -1
  44. package/src/channels/telegram/config-store.mjs +62 -1
  45. package/src/channels/telegram/telegram-controller.mjs +25 -1
  46. package/src/channels/telegram/telegram-runtime.mjs +26 -1
  47. package/src/channels/wecom/wecom-bridge.mjs +3 -2
  48. package/src/channels/weixin/weixin-api.mjs +1 -1
  49. package/src/channels/weixin/weixin-bridge.mjs +3 -2
@@ -1,9 +1,15 @@
1
1
  import { TokenBotController } from '../shared/token-bot-controller.mjs';
2
- import { deriveTelegramBotIdentity, maskTelegramBotId } from './config-store.mjs';
2
+ import {
3
+ deriveTelegramBotIdentity,
4
+ maskTelegramBotId,
5
+ normalizeTelegramAccessPolicy,
6
+ } from './config-store.mjs';
3
7
  import { inspectTelegramToken } from './telegram-api.mjs';
4
8
  import { TELEGRAM_DESCRIPTOR } from './telegram-bridge.mjs';
5
9
 
6
10
  export class TelegramController extends TokenBotController {
11
+ #configStore;
12
+
7
13
  constructor(options) {
8
14
  super({
9
15
  ...options,
@@ -12,5 +18,23 @@ export class TelegramController extends TokenBotController {
12
18
  deriveIdentity: deriveTelegramBotIdentity,
13
19
  maskPlatformId: maskTelegramBotId,
14
20
  });
21
+ this.#configStore = options.configStore;
22
+ }
23
+
24
+ status() {
25
+ const snapshot = super.status();
26
+ return {
27
+ ...snapshot,
28
+ bots: snapshot.bots.map((bot) => {
29
+ const config = this.#configStore.get(bot.botId);
30
+ const accessPolicy = normalizeTelegramAccessPolicy(config ?? {});
31
+ return { ...bot, accessPolicy };
32
+ }),
33
+ };
34
+ }
35
+
36
+ async setAccessPolicy(botId, value) {
37
+ const accessPolicy = normalizeTelegramAccessPolicy(value);
38
+ return this.updateBotConfig(botId, (config) => ({ ...config, ...accessPolicy }));
15
39
  }
16
40
  }
@@ -1,6 +1,10 @@
1
1
  import { createEditableMessageStream, splitMessageText } from '../shared/editable-message-stream.mjs';
2
2
  import { TelegramApi } from './telegram-api.mjs';
3
3
  import { createTelegramBridgeStatus, TelegramHarnessBridge } from './telegram-bridge.mjs';
4
+ import {
5
+ TELEGRAM_ACCESS_MODES,
6
+ normalizeTelegramAccessPolicy,
7
+ } from './config-store.mjs';
4
8
 
5
9
  function escaped(value) {
6
10
  return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
@@ -115,6 +119,16 @@ export function normalizeTelegramUpdate(update, { botId, username, loadFile = as
115
119
  };
116
120
  }
117
121
 
122
+ export function telegramInboundAllowed(message, {
123
+ accessMode = TELEGRAM_ACCESS_MODES.compatible,
124
+ allowedPrivateUserIds = new Set(),
125
+ } = {}) {
126
+ if (accessMode !== TELEGRAM_ACCESS_MODES.privateAllowlist) return true;
127
+ return message?.kind === 'direct'
128
+ && allowedPrivateUserIds instanceof Set
129
+ && allowedPrivateUserIds.has(String(message.senderId));
130
+ }
131
+
118
132
  class TelegramBotClient {
119
133
  #api;
120
134
  #signal;
@@ -198,6 +212,8 @@ export class TelegramRuntime {
198
212
  #logger;
199
213
  #replyTimeoutMs;
200
214
  #createApi;
215
+ #accessMode;
216
+ #allowedPrivateUserIds;
201
217
  #status = createTelegramRuntimeStatus();
202
218
  #api = null;
203
219
  #bridge = null;
@@ -224,6 +240,9 @@ export class TelegramRuntime {
224
240
  this.#logger = logger;
225
241
  this.#replyTimeoutMs = replyTimeoutMs;
226
242
  this.#createApi = createApi;
243
+ const accessPolicy = normalizeTelegramAccessPolicy(config);
244
+ this.#accessMode = accessPolicy.accessMode;
245
+ this.#allowedPrivateUserIds = new Set(accessPolicy.allowedUsers);
227
246
  }
228
247
 
229
248
  get status() {
@@ -323,7 +342,10 @@ export class TelegramRuntime {
323
342
  username: this.#config.username,
324
343
  loadFile: (fileId, options) => this.#api.downloadFile({ fileId, ...options }),
325
344
  });
326
- if (message) {
345
+ if (message && telegramInboundAllowed(message, {
346
+ accessMode: this.#accessMode,
347
+ allowedPrivateUserIds: this.#allowedPrivateUserIds,
348
+ })) {
327
349
  void this.#bridge.accept(message).catch((error) => {
328
350
  if (signal.aborted) return;
329
351
  this.#logger.error?.(
@@ -331,6 +353,9 @@ export class TelegramRuntime {
331
353
  error,
332
354
  );
333
355
  });
356
+ } else if (message) {
357
+ this.#status.messagesRejected += 1;
358
+ this.#status.lastRejectedAt = new Date().toISOString();
334
359
  }
335
360
  cursor = update.update_id + 1;
336
361
  await this.#state.setCursor(cursor);
@@ -34,8 +34,9 @@ const HELP_TEXT = [
34
34
  '/workspacelist 列出工作区绝对路径',
35
35
  '/sessionlist [工作区序号或绝对路径] 列出会话 ID 和标题',
36
36
  '/session Session ID 或当前工作区序号 将当前聊天绑定到指定会话',
37
- '/models 列出所有可用模型',
38
- '/model [模型ID] 查看或切换当前会话模型',
37
+ '/models 按序号列出所有可用模型',
38
+ '/model [序号或完整模型ID] 查看或切换当前会话模型',
39
+ '示例:先发 /models,再发 /model 2',
39
40
  '/stop 停止当前任务',
40
41
  '/steer 补充指令 纠偏当前任务',
41
42
  '/status 检查连接状态',
@@ -184,7 +184,7 @@ function authenticatedHeaders(token) {
184
184
  function baseInfo() {
185
185
  return {
186
186
  channel_version: WEIXIN_PROTOCOL_VERSION,
187
- bot_agent: 'DeepSeekHarness/0.12.0',
187
+ bot_agent: 'DeepSeekHarness/0.14.0',
188
188
  };
189
189
  }
190
190
 
@@ -40,8 +40,9 @@ const HELP_TEXT = [
40
40
  '/workspacelist 列出工作区绝对路径',
41
41
  '/sessionlist [工作区序号或绝对路径] 列出会话 ID 和标题',
42
42
  '/session Session ID 或当前工作区序号 将当前聊天绑定到指定会话',
43
- '/models 列出所有可用模型',
44
- '/model [模型ID] 查看或切换当前会话模型',
43
+ '/models 按序号列出所有可用模型',
44
+ '/model [序号或完整模型ID] 查看或切换当前会话模型',
45
+ '示例:先发 /models,再发 /model 2',
45
46
  '/stop 停止当前任务',
46
47
  '/steer 补充指令 纠偏当前任务',
47
48
  '/status 检查连接状态',