@xmanrui/dsh-im 4.27.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/README.en.md +4 -4
- package/README.md +4 -4
- package/lib/client.js +1 -1
- package/lib/index.js +292 -288
- package/package.json +1 -1
- package/plugin-src/host/channels/dingtalk/production.mjs +1 -1
- package/plugin-src/host/channels/feishu/production.mjs +1 -1
- package/plugin-src/host/channels/qq/production.mjs +1 -1
- package/plugin-src/host/channels/shared/production.mjs +1 -1
- package/plugin-src/host/channels/slack/production.mjs +1 -1
- package/plugin-src/host/channels/wecom/production.mjs +1 -1
- package/plugin-src/host/channels/wecom-app/production.mjs +1 -1
- package/plugin-src/host/channels/weixin/production.mjs +22 -5
- package/plugin-src/host/channels/whatsapp/production.mjs +1 -1
- package/src/channels/feishu/bridge.mjs +96 -98
- package/src/channels/feishu/feishu-cards.mjs +178 -7
- package/src/channels/feishu/message-utils.mjs +10 -1
- package/src/channels/shared/bot-workspace-store.mjs +30 -10
- package/src/channels/shared/default-workspace.mjs +6 -3
- package/src/channels/shared/harness-session-binding.mjs +4 -0
- package/src/channels/shared/i18n-en/feishu.mjs +1 -0
- package/src/channels/weixin/weixin-api.mjs +3 -2
|
@@ -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,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// English translations (feishu area). Keys are exact Chinese literals passed to t().
|
|
2
2
|
export default {
|
|
3
|
+
'内容已合并至后续消息。': 'Content has been consolidated into the following messages.',
|
|
3
4
|
// feishu/bridge.mjs — welcome / help
|
|
4
5
|
'北汇星河 AIOS 已连接 DeepSeek Harness。':
|
|
5
6
|
'BeiHui XingHe AIOS is connected to DeepSeek Harness.',
|
|
@@ -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(
|
|
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);
|