@xmanrui/dsh-im 4.28.0 → 4.28.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmanrui/dsh-im",
3
- "version": "4.28.0",
3
+ "version": "4.28.1",
4
4
  "description": "把十二种 IM 渠道和公网 AI Office 接入本机 DeepSeek Harness。 Connect twelve IM channels and a public AI Office to a local DeepSeek Harness.",
5
5
  "keywords": [
6
6
  "deepseek-harness",
@@ -63,7 +63,7 @@ export async function createProductionController(ctx, config = {}, internals = {
63
63
  const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
64
64
  const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
65
65
  const workspaces = internals.workspaces
66
- ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace }).load();
66
+ ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load();
67
67
  const canListConfiguredBots = typeof configStore.list === 'function';
68
68
  const configuredBots = canListConfiguredBots ? configStore.list() : [];
69
69
  if (canListConfiguredBots) {
@@ -122,7 +122,7 @@ export async function createProductionController(ctx, config = {}, internals = {
122
122
  const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
123
123
  const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
124
124
  const workspaces = internals.workspaces
125
- ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace }).load();
125
+ ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load();
126
126
  const canListConfiguredBots = typeof configStore.list === 'function';
127
127
  const listConfiguredBots = () => canListConfiguredBots ? configStore.list() : [];
128
128
  const configuredBots = listConfiguredBots();
@@ -60,7 +60,7 @@ export async function createProductionController(ctx, config = {}, internals = {
60
60
  const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
61
61
  const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
62
62
  const workspaces = internals.workspaces
63
- ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace }).load();
63
+ ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load();
64
64
  const configuredBots = configStore.list();
65
65
  await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
66
66
  await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
@@ -70,7 +70,7 @@ export async function createTokenProductionController(ctx, config, internals, de
70
70
  const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
71
71
  const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
72
72
  const workspaces = internals.workspaces
73
- ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace }).load();
73
+ ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load();
74
74
  const configuredBots = configStore.list();
75
75
  await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
76
76
  await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
@@ -49,7 +49,7 @@ export async function createProductionController(ctx, config = {}, internals = {
49
49
  const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
50
50
  const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
51
51
  const workspaces = internals.workspaces
52
- ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace }).load();
52
+ ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load();
53
53
  const configuredBots = configStore.list();
54
54
  await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
55
55
  await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
@@ -60,7 +60,7 @@ export async function createProductionController(ctx, config = {}, internals = {
60
60
  const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
61
61
  const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
62
62
  const workspaces = internals.workspaces
63
- ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace }).load();
63
+ ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load();
64
64
  const configuredBots = configStore.list();
65
65
  await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
66
66
  await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
@@ -74,7 +74,7 @@ export async function createProductionController(ctx, config = {}, internals = {
74
74
  const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
75
75
  const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
76
76
  const workspaces = internals.workspaces
77
- ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace }).load();
77
+ ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load();
78
78
  const configuredBots = configStore.list();
79
79
  await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
80
80
  await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
@@ -2,6 +2,7 @@ import { getImageInputSettingsStore } from '../../../../src/channels/shared/imag
2
2
  import { unlink } from 'node:fs/promises';
3
3
  import { homedir } from 'node:os';
4
4
  import { join, resolve } from 'node:path';
5
+ import { EnvHttpProxyAgent, fetch as undiciFetch } from 'undici';
5
6
 
6
7
  import { WeixinConfigStore } from '../../../../src/channels/weixin/config-store.mjs';
7
8
  import { HarnessClient } from '../../../../src/channels/weixin/harness-client.mjs';
@@ -83,7 +84,14 @@ export async function createProductionController(ctx, config = {}, internals = {
83
84
  const Harness = internals.HarnessClient ?? HarnessClient;
84
85
  const Controller = internals.Controller ?? WeixinController;
85
86
  const Runtime = internals.Runtime ?? WeixinRuntime;
86
- const api = internals.api ?? createWeixinApi();
87
+ let uploadDispatcher;
88
+ const api = internals.api ?? createWeixinApi({
89
+ uploadFetchImpl: (url, options) => {
90
+ // Keep CDN response headers independent of the host's global dispatcher.
91
+ uploadDispatcher ??= new EnvHttpProxyAgent();
92
+ return undiciFetch(url, { ...options, dispatcher: uploadDispatcher });
93
+ },
94
+ });
87
95
  const createSupervisor = internals.createConnectionSupervisor ?? createConnectionSupervisor;
88
96
  const logger = typeof ctx.logger === 'function'
89
97
  ? ctx.logger('dsh-weixin')
@@ -95,7 +103,7 @@ export async function createProductionController(ctx, config = {}, internals = {
95
103
  const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
96
104
  const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
97
105
  const workspaces = diagnosticWorkspaces(internals.workspaces
98
- ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace }).load());
106
+ ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load());
99
107
  const configuredBots = configStore.list();
100
108
  await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
101
109
  await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
@@ -232,9 +240,18 @@ export async function createProductionController(ctx, config = {}, internals = {
232
240
  }),
233
241
  ready: supervisor.ready,
234
242
  async close() {
235
- await supervisor.close();
236
- await controller.close();
237
- harness.stopManagedProcess();
243
+ try {
244
+ await supervisor.close();
245
+ await controller.close();
246
+ } finally {
247
+ const dispatcher = uploadDispatcher;
248
+ uploadDispatcher = undefined;
249
+ try {
250
+ await dispatcher?.destroy();
251
+ } finally {
252
+ harness.stopManagedProcess();
253
+ }
254
+ }
238
255
  },
239
256
  };
240
257
  }
@@ -70,7 +70,7 @@ export async function createProductionController(ctx, config = {}, internals = {
70
70
  const { defaultWorkspace, ungroupedWorkspace } = await prepareBotWorkspace(config);
71
71
  const WorkspaceStore = internals.WorkspaceStore ?? BotWorkspaceStore;
72
72
  const workspaces = internals.workspaces
73
- ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace }).load();
73
+ ?? await new WorkspaceStore(paths.workspaces, { defaultWorkspace, ungroupedWorkspace }).load();
74
74
  const configuredBots = configStore.list();
75
75
  await workspaces.reconcile(configuredBots.map((bot) => bot.botId));
76
76
  await Promise.all(configuredBots.map((bot) => workspaces.ensure(bot.botId, {
@@ -4980,8 +4980,14 @@ export class FeishuHarnessBridge {
4980
4980
  });
4981
4981
  // 流式卡片模式:每轮一张过程卡(原地 patch),过程与最终答案都进卡;
4982
4982
  // post 模式维持逐条直推。先预建卡片状态,纯问答回合也能在收尾时开卡。
4983
- const streamingCard = this.#stepPushMode === FEISHU_STEP_PUSH_MODES.STREAMING_CARD;
4983
+ // 飞书原生思考过程按 chat_id 创建,不会落进话题(#244);话题内的回合改用
4984
+ // 实时过程卡(以 reply_in_thread 回复留在话题内),避免过程出现在话题外。
4985
+ const liveCotInTopic = this.#stepPushMode === FEISHU_STEP_PUSH_MODES.LIVE_COT
4986
+ && this.#replyInThreadFor(messageId);
4987
+ const streamingCard = this.#stepPushMode === FEISHU_STEP_PUSH_MODES.STREAMING_CARD
4988
+ || liveCotInTopic;
4984
4989
  const liveCot = this.#stepPushMode === FEISHU_STEP_PUSH_MODES.LIVE_COT
4990
+ && !liveCotInTopic
4985
4991
  && typeof this.#channel?.createCot === 'function'
4986
4992
  && typeof this.#channel?.writeCotEvents === 'function';
4987
4993
  const cot = liveCot
@@ -1,7 +1,7 @@
1
1
  import { t } from './i18n.mjs';
2
2
  import { atConnectionStage, connectionStageError, extractConnectionEvidence } from './connection-error.mjs';
3
3
  import { validateBotAlias, withBotAlias } from './bot-alias.mjs';
4
- import { defaultImWorkspace, sameWorkspacePath } from './default-workspace.mjs';
4
+ import { defaultImWorkspace, ensureImWorkspaceDirectory, sameWorkspacePath } from './default-workspace.mjs';
5
5
  import {
6
6
  mkdir,
7
7
  readFile,
@@ -367,13 +367,14 @@ async function writeStoredDocument(path, document) {
367
367
  await rename(temporary, path);
368
368
  }
369
369
 
370
- export async function validateWorkspacePath(value) {
370
+ export async function validateWorkspacePath(value, { ungroupedWorkspace } = {}) {
371
371
  if (typeof value !== 'string' || !value.trim() || !isAbsolute(value.trim())) {
372
372
  const error = new Error('工作区必须是绝对路径。');
373
373
  error.code = 'workspace-not-absolute';
374
374
  throw error;
375
375
  }
376
376
  const workspace = resolve(value.trim());
377
+ await ensureImWorkspaceDirectory(workspace, ungroupedWorkspace);
377
378
  let info;
378
379
  try {
379
380
  info = await stat(workspace);
@@ -393,6 +394,7 @@ export async function validateWorkspacePath(value) {
393
394
  export class BotWorkspaceStore {
394
395
  #path;
395
396
  #defaultWorkspace;
397
+ #ungroupedWorkspace;
396
398
  #version = 1;
397
399
  #workspaces = {};
398
400
  #agentPresets = {};
@@ -414,10 +416,11 @@ export class BotWorkspaceStore {
414
416
  #writeQueue = Promise.resolve();
415
417
  #botQueues = new Map();
416
418
 
417
- constructor(path, { defaultWorkspace = defaultImWorkspace() } = {}) {
419
+ constructor(path, { defaultWorkspace = defaultImWorkspace(), ungroupedWorkspace } = {}) {
418
420
  if (typeof path !== 'string' || !path) throw new TypeError('workspace store path is required');
419
421
  this.#path = path;
420
422
  this.#defaultWorkspace = resolve(defaultWorkspace);
423
+ this.#ungroupedWorkspace = ungroupedWorkspace;
421
424
  }
422
425
 
423
426
  async load() {
@@ -691,11 +694,20 @@ export class BotWorkspaceStore {
691
694
  const createsBot = !this.#workspaces[id];
692
695
  const initializesAccessPolicy = initialAccessPolicy !== undefined
693
696
  && !Object.hasOwn(this.#accessPolicies, id);
697
+ const accessPolicy = initializesAccessPolicy
698
+ ? validateAccessPolicy(initialAccessPolicy)
699
+ : undefined;
700
+ const agentPreset = createsBot ? validateAgentPresetId(defaultAgentPreset) : null;
701
+ // Resolve saved bot/conversation choices before preparing the shared IM
702
+ // directory. Merely loading a channel must not create an unused fallback.
703
+ const selectedWorkspaces = new Set([
704
+ this.#workspaces[id] ?? initialWorkspace,
705
+ ...Object.values(this.#conversationWorkspaces[id] ?? {}),
706
+ ]);
707
+ for (const selected of selectedWorkspaces) {
708
+ await ensureImWorkspaceDirectory(selected, this.#ungroupedWorkspace);
709
+ }
694
710
  if (createsBot || initializesAccessPolicy) {
695
- const accessPolicy = initializesAccessPolicy
696
- ? validateAccessPolicy(initialAccessPolicy)
697
- : undefined;
698
- const agentPreset = createsBot ? validateAgentPresetId(defaultAgentPreset) : null;
699
711
  const hadAgentPreset = Object.hasOwn(this.#agentPresets, id);
700
712
  const previousAgentPreset = this.#agentPresets[id];
701
713
  const nextAccessPolicies = initializesAccessPolicy
@@ -744,7 +756,7 @@ export class BotWorkspaceStore {
744
756
  error.code = 'workspace-bot-not-found';
745
757
  throw error;
746
758
  }
747
- const workspace = await validateWorkspacePath(value);
759
+ const workspace = await validateWorkspacePath(value, { ungroupedWorkspace: this.#ungroupedWorkspace });
748
760
  return this.#enqueue(id, async () => {
749
761
  if (!this.has(id)
750
762
  || (incarnation !== undefined && incarnation !== this.incarnationFor(id))) {
@@ -965,7 +977,9 @@ export class BotWorkspaceStore {
965
977
  }
966
978
  // Validate before queueing so an invalid path fails without disturbing the
967
979
  // conversation's current workspace or its session.
968
- const workspace = value === null ? null : await validateWorkspacePath(value);
980
+ const workspace = value === null ? null : await validateWorkspacePath(value, {
981
+ ungroupedWorkspace: this.#ungroupedWorkspace,
982
+ });
969
983
  return this.#enqueue(id, async () => {
970
984
  const assertCurrentSwitch = () => {
971
985
  if (!this.has(id)
@@ -981,6 +995,10 @@ export class BotWorkspaceStore {
981
995
  }
982
996
  };
983
997
  assertCurrentSwitch();
998
+ if (workspace === null) {
999
+ await ensureImWorkspaceDirectory(this.workspaceFor(id), this.#ungroupedWorkspace);
1000
+ assertCurrentSwitch();
1001
+ }
984
1002
  const previousOverrides = this.#conversationWorkspaces[id];
985
1003
  const previous = previousOverrides?.[key];
986
1004
  const hadOverride = Boolean(previousOverrides)
@@ -1065,7 +1083,9 @@ export class BotWorkspaceStore {
1065
1083
  );
1066
1084
  }
1067
1085
  };
1068
- const workspace = await canonicalWorkspacePath(await validateWorkspacePath(value));
1086
+ const workspace = await canonicalWorkspacePath(await validateWorkspacePath(value, {
1087
+ ungroupedWorkspace: this.#ungroupedWorkspace,
1088
+ }));
1069
1089
  return this.#enqueue(id, async () => {
1070
1090
  if (!this.has(id)
1071
1091
  || (incarnation !== undefined && incarnation !== this.incarnationFor(id))) {
@@ -21,8 +21,11 @@ export async function sameWorkspacePath(left, right) {
21
21
  export async function prepareBotWorkspace(config = {}) {
22
22
  const ungroupedWorkspace = defaultImWorkspace(config);
23
23
  const defaultWorkspace = resolve(config.workspace ?? ungroupedWorkspace);
24
- if (await sameWorkspacePath(defaultWorkspace, ungroupedWorkspace)) {
25
- await mkdir(defaultWorkspace, { recursive: true });
26
- }
27
24
  return { defaultWorkspace, ungroupedWorkspace };
28
25
  }
26
+
27
+ export async function ensureImWorkspaceDirectory(workspace, ungroupedWorkspace) {
28
+ if (await sameWorkspacePath(workspace, ungroupedWorkspace)) {
29
+ await mkdir(workspace, { recursive: true });
30
+ }
31
+ }
@@ -1,3 +1,4 @@
1
+ import { mkdir } from 'node:fs/promises';
1
2
  import { isAbsolute } from 'node:path';
2
3
 
3
4
  const MAX_SESSION_ID_LENGTH = 256;
@@ -99,6 +100,9 @@ export async function adoptRegisteredWorkspaceSession(client, value, options = {
99
100
  }
100
101
  workspace = { path: summary.cwd };
101
102
  }
103
+ if (await client.isUngroupedWorkspace?.(workspace.path)) {
104
+ await mkdir(workspace.path, { recursive: true });
105
+ }
102
106
  const adopted = await client.rpc('session.create', {
103
107
  ...(workspace.workspaceId ? { workspaceId: workspace.workspaceId } : { cwd: workspace.path }),
104
108
  sessionId,
@@ -504,8 +504,9 @@ function validateLoginResponse(value) {
504
504
  return value;
505
505
  }
506
506
 
507
- export function createWeixinApi({ fetchImpl = fetch } = {}) {
507
+ export function createWeixinApi({ fetchImpl = fetch, uploadFetchImpl = fetchImpl } = {}) {
508
508
  if (typeof fetchImpl !== 'function') throw new TypeError('fetchImpl must be a function');
509
+ if (typeof uploadFetchImpl !== 'function') throw new TypeError('uploadFetchImpl must be a function');
509
510
 
510
511
  async function sendArtifact({
511
512
  baseUrl,
@@ -566,7 +567,7 @@ export function createWeixinApi({ fetchImpl = fetch } = {}) {
566
567
  const ciphertextSize = aesEcbPaddedSize(file.bytes.byteLength);
567
568
  let downloadParam;
568
569
  try {
569
- downloadParam = await uploadWeixinCdn(fetchImpl, uploadUrl, file.bytes, aesKey, { signal });
570
+ downloadParam = await uploadWeixinCdn(uploadFetchImpl, uploadUrl, file.bytes, aesKey, { signal });
570
571
  } catch (error) {
571
572
  if (signal?.aborted) throw abortError(signal);
572
573
  const status = Number(error?.status);