@xmanrui/dsh-im 5.9.1 → 5.11.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.
- package/PROACTIVE_DELIVERY.en.md +33 -9
- package/PROACTIVE_DELIVERY.md +33 -9
- package/README.en.md +42 -7
- package/README.md +46 -8
- package/bin/dsh-im.mjs +65 -0
- package/docs/client-integration.md +4 -0
- package/lib/client.js +1735 -203
- package/lib/index.js +367 -341
- package/package.json +7 -6
- package/plugin-src/client/access-policy-settings.js +210 -12
- package/plugin-src/client/bot-general-settings.js +44 -3
- package/plugin-src/client/delivery-settings.js +2 -0
- package/plugin-src/client/delivery-sync-settings.js +269 -0
- package/plugin-src/client/global-settings.js +45 -7
- package/plugin-src/client/i18n-ru.js +112 -0
- package/plugin-src/client/i18n.js +110 -0
- package/plugin-src/client/im-channels.js +419 -0
- package/plugin-src/client/index.js +50 -2
- package/plugin-src/client/model-setting.js +6 -3
- package/plugin-src/client/styles.js +23 -7
- package/plugin-src/client/update-panel.js +2 -1
- package/plugin-src/host/channel-list-rpc.mjs +280 -0
- package/plugin-src/host/channels/dingtalk/production.mjs +28 -10
- package/plugin-src/host/channels/dingtalk/rpc.mjs +10 -1
- package/plugin-src/host/channels/feishu/production.mjs +50 -37
- package/plugin-src/host/channels/feishu/rpc.mjs +10 -1
- package/plugin-src/host/channels/matrix/production.mjs +28 -10
- package/plugin-src/host/channels/matrix/rpc.mjs +10 -0
- package/plugin-src/host/channels/qq/production.mjs +30 -11
- package/plugin-src/host/channels/qq/rpc.mjs +10 -1
- package/plugin-src/host/channels/shared/access-policy-production.mjs +9 -0
- package/plugin-src/host/channels/shared/binding-events.mjs +109 -0
- package/plugin-src/host/channels/shared/production.mjs +14 -1
- package/plugin-src/host/channels/shared/reply-content-rpc.mjs +17 -0
- package/plugin-src/host/channels/shared/rpc.mjs +9 -0
- package/plugin-src/host/channels/shared/workspace-rpc.mjs +1 -0
- package/plugin-src/host/channels/slack/production.mjs +28 -10
- package/plugin-src/host/channels/slack/rpc.mjs +10 -0
- package/plugin-src/host/channels/telegram/production.mjs +5 -0
- package/plugin-src/host/channels/wecom/production.mjs +28 -10
- package/plugin-src/host/channels/wecom/rpc.mjs +10 -1
- package/plugin-src/host/channels/wecom-app/production.mjs +28 -10
- package/plugin-src/host/channels/wecom-app/rpc.mjs +9 -0
- package/plugin-src/host/channels/weixin/production.mjs +28 -10
- package/plugin-src/host/channels/weixin/rpc.mjs +10 -1
- package/plugin-src/host/channels/whatsapp/production.mjs +28 -10
- package/plugin-src/host/channels/whatsapp/rpc.mjs +10 -1
- package/plugin-src/host/delivery-adapter.mjs +35 -20
- package/plugin-src/host/delivery-service.mjs +99 -1
- package/plugin-src/host/delivery-suggestions.mjs +31 -1
- package/plugin-src/host/delivery-sync-rpc.mjs +100 -0
- package/plugin-src/host/harness-connection.mjs +2 -1
- package/plugin-src/host/harness-peer.mjs +3 -1
- package/plugin-src/host/host-language-rpc.mjs +16 -2
- package/plugin-src/host/host-language.mjs +29 -0
- package/plugin-src/host/index.mjs +30 -1
- package/plugin-src/host/modern-harness-api.mjs +5 -1
- package/plugin-src/host/root-scope.mjs +32 -0
- package/plugin-src/host/session-sync-coordinator.mjs +290 -122
- package/plugin-src/host/session-sync-targets.mjs +71 -0
- package/plugin-src/management-rpc.mjs +18 -2
- package/scripts/verify-package.mjs +48 -10
- package/src/channels/dingtalk/dingtalk-bridge.mjs +50 -6
- package/src/channels/dingtalk/state-store.mjs +56 -0
- package/src/channels/discord/discord-api.mjs +2 -1
- package/src/channels/feishu/bridge.mjs +154 -58
- package/src/channels/feishu/feishu-cards.mjs +10 -4
- package/src/channels/feishu/feishu-runtime.mjs +11 -3
- package/src/channels/feishu/message-utils.mjs +106 -30
- package/src/channels/feishu/slash-command-panel.mjs +26 -0
- package/src/channels/feishu/state-store.mjs +14 -0
- package/src/channels/matrix/matrix-api.mjs +2 -1
- package/src/channels/qq/qq-bridge.mjs +114 -14
- package/src/channels/qq/state-store.mjs +55 -1
- package/src/channels/shared/access-policy.mjs +60 -7
- package/src/channels/shared/action-card.mjs +83 -7
- package/src/channels/shared/bot-workspace-store.mjs +255 -11
- package/src/channels/shared/busy-message-dispatcher.mjs +2 -2
- package/src/channels/shared/channel-capabilities.mjs +44 -0
- package/src/channels/shared/command-catalog.mjs +68 -3
- package/src/channels/shared/command-permission.mjs +6 -2
- package/src/channels/shared/conversation-state-store.mjs +16 -0
- package/src/channels/shared/deferred-delivery-coordinator.mjs +6 -1
- package/src/channels/shared/deferred-delivery.mjs +4 -0
- package/src/channels/shared/delivery-sync-settings-store.mjs +86 -0
- package/src/channels/shared/delivery-sync-settings.mjs +122 -0
- package/src/channels/shared/diagnostic-details.mjs +6 -1
- package/src/channels/shared/failure-log-file.mjs +79 -0
- package/src/channels/shared/harness-client.mjs +259 -96
- package/src/channels/shared/i18n-en/diagnostics.mjs +1 -0
- package/src/channels/shared/i18n-en/feishu.mjs +2 -2
- package/src/channels/shared/i18n-en/shared-a.mjs +13 -2
- package/src/channels/shared/i18n-en/shared-b.mjs +73 -4
- package/src/channels/shared/i18n-en/shared-d.mjs +144 -0
- package/src/channels/shared/i18n-en/weixin.mjs +4 -0
- package/src/channels/shared/i18n-en.mjs +2 -0
- package/src/channels/shared/i18n-ru/diagnostics.mjs +1 -0
- package/src/channels/shared/i18n-ru/feishu.mjs +2 -2
- package/src/channels/shared/i18n-ru/shared-a.mjs +13 -2
- package/src/channels/shared/i18n-ru/shared-b.mjs +72 -4
- package/src/channels/shared/i18n-ru/shared-d.mjs +144 -0
- package/src/channels/shared/i18n-ru/weixin.mjs +4 -0
- package/src/channels/shared/i18n-ru.mjs +2 -0
- package/src/channels/shared/inbound-access.mjs +10 -0
- package/src/channels/shared/interface-language-store.mjs +49 -10
- package/src/channels/shared/interface-language.mjs +19 -1
- package/src/channels/shared/markdown-chunks.mjs +5 -0
- package/src/channels/shared/message-failure.mjs +22 -1
- package/src/channels/shared/model-setting.mjs +6 -3
- package/src/channels/shared/new-command.mjs +158 -4
- package/src/channels/shared/plan-goal-command.mjs +132 -0
- package/src/channels/shared/qrcode.mjs +5 -0
- package/src/channels/shared/reply-content.mjs +102 -0
- package/src/channels/shared/reset-command.mjs +46 -0
- package/src/channels/shared/semantic/artifact.mjs +133 -29
- package/src/channels/shared/semantic/reply-reference.mjs +18 -3
- package/src/channels/shared/session-nav-command.mjs +999 -0
- package/src/channels/shared/session-ring-support.mjs +184 -0
- package/src/channels/shared/session-ring.mjs +202 -0
- package/src/channels/shared/session-title.mjs +11 -0
- package/src/channels/shared/status-command.mjs +2 -1
- package/src/channels/shared/text-harness-bridge.mjs +166 -7
- package/src/channels/shared/workspace-command.mjs +567 -31
- package/src/channels/shared/workspace-session.mjs +52 -4
- package/src/channels/slack/slack-api.mjs +2 -1
- package/src/channels/telegram/config-store.mjs +10 -2
- package/src/channels/telegram/telegram-api.mjs +19 -1
- package/src/channels/telegram/telegram-rich-message.mjs +17 -5
- package/src/channels/telegram/telegram-runtime.mjs +14 -1
- package/src/channels/wecom/state-store.mjs +13 -1
- package/src/channels/wecom/wecom-bridge.mjs +183 -26
- package/src/channels/wecom-app/state-store.mjs +13 -1
- package/src/channels/wecom-app/wecom-app-bridge.mjs +44 -4
- package/src/channels/weixin/state-store.mjs +13 -1
- package/src/channels/weixin/weixin-bridge.mjs +71 -4
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { registerManagementRpc } from '../management-rpc.mjs';
|
|
2
|
+
import { deliverySyncPatchKeys } from '../../src/channels/shared/delivery-sync-settings.mjs';
|
|
3
|
+
import { getDeliverySyncSettingsStore } from '../../src/channels/shared/delivery-sync-settings-store.mjs';
|
|
4
|
+
import { t } from '../../src/channels/shared/i18n.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Management channel for the delivery-sync settings. It is separate from the
|
|
8
|
+
* loopback-only `/dsh-im-settings` channel on purpose: this page must stay
|
|
9
|
+
* usable from an authenticated domain (the Host dashboard served beyond
|
|
10
|
+
* loopback), so it follows the profile's `rpcAuthority` like the sidebar
|
|
11
|
+
* settings do.
|
|
12
|
+
*/
|
|
13
|
+
export const DELIVERY_SYNC_RPC_CHANNEL = '/dsh-im-delivery-sync';
|
|
14
|
+
|
|
15
|
+
export const DELIVERY_SYNC_ENDPOINTS = Object.freeze({
|
|
16
|
+
get: 'settings.delivery-sync.get',
|
|
17
|
+
set: 'settings.delivery-sync.set',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const ENDPOINTS = new Set(Object.values(DELIVERY_SYNC_ENDPOINTS));
|
|
21
|
+
|
|
22
|
+
const BOOLEAN_FIELDS = new Set(['mirrorUserInput', 'deliverModelAnswers']);
|
|
23
|
+
const ICON_FIELDS = new Set(['inputIcon', 'modelIcon']);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Validate one delivery-sync request. `get` takes an empty object; `set` takes
|
|
27
|
+
* one or more of the four known fields, each with the type it is stored as.
|
|
28
|
+
* An icon that is a string but unusable is accepted here and normalized to the
|
|
29
|
+
* empty prefix by the store, so a reader never loses a save over a pasted
|
|
30
|
+
* emoji sequence.
|
|
31
|
+
*/
|
|
32
|
+
export function validDeliverySyncPayload(endpoint, payload) {
|
|
33
|
+
if (!ENDPOINTS.has(endpoint)) return false;
|
|
34
|
+
if (payload === null || typeof payload !== 'object' || Array.isArray(payload)) return false;
|
|
35
|
+
const keys = deliverySyncPatchKeys(payload);
|
|
36
|
+
if (keys === null) return false;
|
|
37
|
+
if (endpoint === DELIVERY_SYNC_ENDPOINTS.get) return keys.length === 0;
|
|
38
|
+
if (keys.length === 0) return false;
|
|
39
|
+
return keys.every((key) => (BOOLEAN_FIELDS.has(key)
|
|
40
|
+
? typeof payload[key] === 'boolean'
|
|
41
|
+
: ICON_FIELDS.has(key) && typeof payload[key] === 'string'));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function createDeliverySyncRpcHandler(store, { logger = console } = {}) {
|
|
45
|
+
if (!store || typeof store.get !== 'function' || typeof store.set !== 'function') {
|
|
46
|
+
throw new TypeError('createDeliverySyncRpcHandler requires a delivery sync settings store');
|
|
47
|
+
}
|
|
48
|
+
return async (endpoint, payload, signal) => {
|
|
49
|
+
if (!validDeliverySyncPayload(endpoint, payload)) {
|
|
50
|
+
return {
|
|
51
|
+
ok: false,
|
|
52
|
+
error: {
|
|
53
|
+
code: 'bad-request',
|
|
54
|
+
message: t('无效的会话同步设置:开关必须是布尔值,图标是不超过 32 个字符的文本。'),
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (signal?.aborted) {
|
|
59
|
+
return { ok: false, error: { code: 'cancelled', message: t('请求已取消。') } };
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const value = endpoint === DELIVERY_SYNC_ENDPOINTS.get
|
|
63
|
+
? await store.get()
|
|
64
|
+
: await store.set(payload);
|
|
65
|
+
return { ok: true, value };
|
|
66
|
+
} catch (error) {
|
|
67
|
+
// The page only sees a stable code; the Host log keeps the cause, so a
|
|
68
|
+
// damaged document or a permission problem stays diagnosable.
|
|
69
|
+
logger?.warn?.(
|
|
70
|
+
`[dsh-im] delivery-sync settings ${endpoint} failed`
|
|
71
|
+
+ ` [${error?.code ?? error?.name ?? 'unknown-error'}]: ${error?.message ?? ''}`,
|
|
72
|
+
);
|
|
73
|
+
return {
|
|
74
|
+
ok: false,
|
|
75
|
+
error: {
|
|
76
|
+
code: 'delivery-sync-settings-unavailable',
|
|
77
|
+
message: t('无法读取或保存会话同步设置,请稍后重试。'),
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Install-time helper: the store the RPC and the coordinator share. */
|
|
85
|
+
export function deliverySyncStore(config) {
|
|
86
|
+
return getDeliverySyncSettingsStore(config);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Register the delivery-sync settings channel. The authority follows the
|
|
91
|
+
* profile option (`trusted-host` by default) because the settings page is
|
|
92
|
+
* commonly opened through the Host dashboard's own domain rather than
|
|
93
|
+
* 127.0.0.1; `loopback` stays available for operators who pinned it.
|
|
94
|
+
*/
|
|
95
|
+
export function installDeliverySyncRpc(ctx, { config = {}, store = null, logger = console } = {}) {
|
|
96
|
+
const handler = createDeliverySyncRpcHandler(store ?? deliverySyncStore(config), { logger });
|
|
97
|
+
return registerManagementRpc(ctx, DELIVERY_SYNC_RPC_CHANNEL, handler, {
|
|
98
|
+
authority: config.rpcAuthority,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { modernHarnessApi } from './modern-harness-api.mjs';
|
|
2
|
+
import { rootScope } from './root-scope.mjs';
|
|
2
3
|
|
|
3
4
|
/** Connect to this Host directly unless an external Harness URL was configured. */
|
|
4
5
|
export function harnessConnection(ctx, config = {}, { competitiveApprovals = false } = {}) {
|
|
@@ -11,6 +12,6 @@ export function harnessConnection(ctx, config = {}, { competitiveApprovals = fal
|
|
|
11
12
|
competitiveApprovals,
|
|
12
13
|
// Cordis child contexts share one root; different Hosts must not share
|
|
13
14
|
// ownership of pending questions and approvals.
|
|
14
|
-
interactionScope: ctx
|
|
15
|
+
interactionScope: rootScope(ctx),
|
|
15
16
|
};
|
|
16
17
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { rootScope } from './root-scope.mjs';
|
|
2
|
+
|
|
1
3
|
const peers = new WeakMap();
|
|
2
4
|
|
|
3
5
|
/** One caller identity shared by the Host's session and command gateways. */
|
|
4
6
|
export function harnessPeer(ctx) {
|
|
5
|
-
const scope = ctx
|
|
7
|
+
const scope = rootScope(ctx);
|
|
6
8
|
const cached = peers.get(scope);
|
|
7
9
|
if (cached) return cached;
|
|
8
10
|
const connection = ctx?.connection;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { registerManagementRpc } from '../management-rpc.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
normalizeInterfaceLanguageTag,
|
|
4
|
+
normalizeMessageLanguageChoice,
|
|
5
|
+
} from '../../src/channels/shared/interface-language.mjs';
|
|
3
6
|
|
|
4
7
|
export const HOST_LANGUAGE_RPC_CHANNEL = '/dsh-im-language';
|
|
5
8
|
export const HOST_LANGUAGE_ENDPOINTS = Object.freeze({
|
|
6
9
|
get: 'settings.language.get',
|
|
10
|
+
set: 'settings.language.set',
|
|
7
11
|
mirror: 'settings.language.mirror',
|
|
8
12
|
});
|
|
9
13
|
|
|
@@ -13,6 +17,12 @@ export function validHostLanguagePayload(endpoint, payload) {
|
|
|
13
17
|
if (!ENDPOINTS.has(endpoint)) return false;
|
|
14
18
|
if (payload === null || typeof payload !== 'object' || Array.isArray(payload)) return false;
|
|
15
19
|
const keys = Object.keys(payload);
|
|
20
|
+
if (endpoint === HOST_LANGUAGE_ENDPOINTS.set) {
|
|
21
|
+
if (keys.length !== 1 || keys[0] !== 'language') return false;
|
|
22
|
+
// 'auto' clears the explicit choice; a tag must be one the shipped
|
|
23
|
+
// dictionaries can serve, so the page cannot pin a language nobody wrote.
|
|
24
|
+
return normalizeMessageLanguageChoice(payload.language) !== null;
|
|
25
|
+
}
|
|
16
26
|
if (endpoint === HOST_LANGUAGE_ENDPOINTS.mirror) {
|
|
17
27
|
if (keys.length !== 1 || keys[0] !== 'locale') return false;
|
|
18
28
|
// An explicit null clears the mirror; anything else must be a usable tag.
|
|
@@ -28,7 +38,7 @@ export function validHostLanguagePayload(endpoint, payload) {
|
|
|
28
38
|
*/
|
|
29
39
|
export function createHostLanguageRpcHandler({ controller, logger = null } = {}) {
|
|
30
40
|
if (!controller || typeof controller.snapshot !== 'function'
|
|
31
|
-
|| typeof controller.mirror !== 'function') {
|
|
41
|
+
|| typeof controller.mirror !== 'function' || typeof controller.select !== 'function') {
|
|
32
42
|
throw new TypeError('createHostLanguageRpcHandler requires a host language controller');
|
|
33
43
|
}
|
|
34
44
|
return async (endpoint, payload, signal) => {
|
|
@@ -42,6 +52,10 @@ export function createHostLanguageRpcHandler({ controller, logger = null } = {})
|
|
|
42
52
|
if (endpoint === HOST_LANGUAGE_ENDPOINTS.get) {
|
|
43
53
|
return { ok: true, value: controller.snapshot() };
|
|
44
54
|
}
|
|
55
|
+
if (endpoint === HOST_LANGUAGE_ENDPOINTS.set) {
|
|
56
|
+
const choice = normalizeMessageLanguageChoice(payload.language);
|
|
57
|
+
return { ok: true, value: await controller.select(choice === 'auto' ? null : choice) };
|
|
58
|
+
}
|
|
45
59
|
return { ok: true, value: await controller.mirror(payload.locale) };
|
|
46
60
|
} catch (error) {
|
|
47
61
|
// The failure is almost always a settings-directory write problem; keep
|
|
@@ -60,8 +60,11 @@ export function createHostLanguageController({
|
|
|
60
60
|
|
|
61
61
|
const mirrorTag = () => (typeof store?.getLanguageTag === 'function' ? store.getLanguageTag() : null);
|
|
62
62
|
|
|
63
|
+
const explicitTag = () => (typeof store?.getExplicitTag === 'function' ? store.getExplicitTag() : null);
|
|
64
|
+
|
|
63
65
|
const resolution = () => resolveHostLanguageTag({
|
|
64
66
|
config: configLanguage,
|
|
67
|
+
explicit: explicitTag(),
|
|
65
68
|
settings: settingsTag(),
|
|
66
69
|
mirror: mirrorTag(),
|
|
67
70
|
});
|
|
@@ -85,6 +88,32 @@ export function createHostLanguageController({
|
|
|
85
88
|
/** The resolution as it stands, without switching the active language. */
|
|
86
89
|
snapshot: () => describe(resolution()),
|
|
87
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Pin the plugin's own message language, or pass null (the settings page's
|
|
93
|
+
* "same as the DSH interface") to clear that selection. It outranks DSH's
|
|
94
|
+
* locale, so a reader who wants English DSH with Russian bot messages can
|
|
95
|
+
* say so; an operator's `language` option still outranks both.
|
|
96
|
+
*/
|
|
97
|
+
async select(value) {
|
|
98
|
+
const choice = value === null || value === undefined ? null : value;
|
|
99
|
+
if (typeof store?.setExplicitTag !== 'function') return apply();
|
|
100
|
+
if (choice === null) {
|
|
101
|
+
await store.setExplicitTag(null);
|
|
102
|
+
} else {
|
|
103
|
+
const tag = normalizeInterfaceLanguageTag(choice);
|
|
104
|
+
if (tag === null) {
|
|
105
|
+
const error = new Error('Invalid message language selection.');
|
|
106
|
+
error.code = 'interface-language-invalid';
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
await store.setExplicitTag(tag);
|
|
110
|
+
}
|
|
111
|
+
return apply();
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
/** The current explicit selection, or null when the plugin follows DSH. */
|
|
115
|
+
explicit: explicitTag,
|
|
116
|
+
|
|
88
117
|
/** Record the interface locale reported by the settings UI, then re-resolve. */
|
|
89
118
|
async mirror(value) {
|
|
90
119
|
if (typeof store?.setLanguageTag !== 'function') return apply();
|
|
@@ -22,11 +22,16 @@ import { createDeliveryService } from './delivery-service.mjs';
|
|
|
22
22
|
import { createDsBotClient } from './ds-bot-client.mjs';
|
|
23
23
|
import { installDsBotQuestionSync } from './ds-bot-question-sync.mjs';
|
|
24
24
|
import { installInboundTtlRpc } from './inbound-ttl-rpc.mjs';
|
|
25
|
+
import { installDeliverySyncRpc } from './delivery-sync-rpc.mjs';
|
|
25
26
|
import { installSidebarSettingsRpc } from './sidebar-settings.mjs';
|
|
26
27
|
import { installInjectedContext } from './injected-context.mjs';
|
|
27
28
|
import { installSessionSyncCoordinator } from './session-sync-coordinator.mjs';
|
|
29
|
+
import { deliverySwitchesOff } from '../../src/channels/shared/delivery-sync-settings.mjs';
|
|
30
|
+
import { getDeliverySyncSettingsStore } from '../../src/channels/shared/delivery-sync-settings-store.mjs';
|
|
28
31
|
import { installSessionTitlePrefix } from './session-title-prefix.mjs';
|
|
29
32
|
import { installUpdateRpc } from './update-rpc.mjs';
|
|
33
|
+
import { installChannelListRpc } from './channel-list-rpc.mjs';
|
|
34
|
+
import { rootScope } from './root-scope.mjs';
|
|
30
35
|
|
|
31
36
|
export const name = 'dsh-im-host';
|
|
32
37
|
export const inject = [
|
|
@@ -52,6 +57,7 @@ export function createImHostPlugin(internals = {}) {
|
|
|
52
57
|
const startHostLanguageRpc = internals.installHostLanguageRpc ?? installHostLanguageRpc;
|
|
53
58
|
const startUpdate = internals.installUpdateRpc ?? installUpdateRpc;
|
|
54
59
|
const startInboundTtl = internals.installInboundTtlRpc ?? installInboundTtlRpc;
|
|
60
|
+
const startDeliverySync = internals.installDeliverySyncRpc ?? installDeliverySyncRpc;
|
|
55
61
|
const startSidebarSettings = internals.installSidebarSettingsRpc ?? installSidebarSettingsRpc;
|
|
56
62
|
const startInjectedContext = internals.installInjectedContext ?? installInjectedContext;
|
|
57
63
|
const startDelivery = internals.installDeliveryRpc ?? installDeliveryRpc;
|
|
@@ -101,6 +107,21 @@ export function createImHostPlugin(internals = {}) {
|
|
|
101
107
|
unavailableSessionSyncChannels: unavailableSessionSyncChannels.map((channel) => channel === 'wecomApp' ? 'wecom-app' : channel),
|
|
102
108
|
dsBot: createDsBotClient(ctx),
|
|
103
109
|
});
|
|
110
|
+
// The delivery switches are the master for everything that follows a Session
|
|
111
|
+
// through its targets: with both off, `listSessionSyncTargets` answers empty,
|
|
112
|
+
// so neither the coordinator nor a channel's own mirror (Feishu card) sends.
|
|
113
|
+
// A settings read failure must not disable delivery, so it falls through.
|
|
114
|
+
if (typeof deliveryService.listSessionSyncTargets === 'function') {
|
|
115
|
+
const rawListSessionSyncTargets = deliveryService.listSessionSyncTargets.bind(deliveryService);
|
|
116
|
+
deliveryService.listSessionSyncTargets = async (sessionId) => {
|
|
117
|
+
try {
|
|
118
|
+
if (deliverySwitchesOff(await getDeliverySyncSettingsStore(config).get())) return [];
|
|
119
|
+
} catch {
|
|
120
|
+
// keep the unwrapped behaviour
|
|
121
|
+
}
|
|
122
|
+
return rawListSessionSyncTargets(sessionId);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
104
125
|
/** Sessions already reported, so the log stays one line per session. */
|
|
105
126
|
const describedSessions = new Set();
|
|
106
127
|
const describeConversationLogged = async (sessionId) => {
|
|
@@ -125,6 +146,7 @@ export function createImHostPlugin(internals = {}) {
|
|
|
125
146
|
historyChecked: (botId, route, query, options) => deliveryService.historyChecked(botId, route, query, options),
|
|
126
147
|
replyChecked: (botId, route, text, options) => deliveryService.replyChecked(botId, route, text, options),
|
|
127
148
|
describeConversation: (sessionId) => describeConversationLogged(sessionId),
|
|
149
|
+
|
|
128
150
|
// Prompt assembly is synchronous, so a caller that needs the identity
|
|
129
151
|
// before the first step cannot await the async variant.
|
|
130
152
|
describeConversationSync: (sessionId) => deliveryService.describeConversationSync(sessionId),
|
|
@@ -213,6 +235,7 @@ export function createImHostPlugin(internals = {}) {
|
|
|
213
235
|
}
|
|
214
236
|
try {
|
|
215
237
|
startInboundTtl(ctx, { config });
|
|
238
|
+
startDeliverySync(ctx, { config });
|
|
216
239
|
} catch (error) {
|
|
217
240
|
logger.error?.('[dsh-im] failed to activate inbound TTL settings; continuing with channels', error);
|
|
218
241
|
}
|
|
@@ -221,6 +244,11 @@ export function createImHostPlugin(internals = {}) {
|
|
|
221
244
|
} catch (error) {
|
|
222
245
|
logger.error?.('[dsh-im] failed to activate delivery management; continuing with channels', error);
|
|
223
246
|
}
|
|
247
|
+
try {
|
|
248
|
+
installChannelListRpc(ctx, config.rpcAuthority, { dshHome: config.dshHome });
|
|
249
|
+
} catch (error) {
|
|
250
|
+
logger.error?.('[dsh-im] failed to activate channel list; continuing with channels', error);
|
|
251
|
+
}
|
|
224
252
|
}
|
|
225
253
|
const failures = [];
|
|
226
254
|
// Each channel mounts its management RPC before awaiting initialization.
|
|
@@ -240,7 +268,8 @@ export function createImHostPlugin(internals = {}) {
|
|
|
240
268
|
try {
|
|
241
269
|
startSessionSync(ctx, deliveryService, {
|
|
242
270
|
logger,
|
|
243
|
-
inputScope: ctx
|
|
271
|
+
inputScope: rootScope(ctx),
|
|
272
|
+
config,
|
|
244
273
|
});
|
|
245
274
|
installDsBotQuestionSync(ctx, deliveryService, { logger });
|
|
246
275
|
} catch (error) {
|
|
@@ -4,6 +4,7 @@ import { activeHarnessInteractionOwner, clearModelCatalogCache, hasActiveHarness
|
|
|
4
4
|
import { extractConnectionEvidence } from '../../src/channels/shared/connection-error.mjs';
|
|
5
5
|
import { harnessPeer } from './harness-peer.mjs';
|
|
6
6
|
import { sameWorkspacePath } from '../../src/channels/shared/default-workspace.mjs';
|
|
7
|
+
import { rootScope } from './root-scope.mjs';
|
|
7
8
|
|
|
8
9
|
const modernApis = new WeakMap();
|
|
9
10
|
|
|
@@ -251,6 +252,9 @@ class ModernHarnessApi {
|
|
|
251
252
|
rename: (request, signal) => rpcResult(request, () => this.#invoke(
|
|
252
253
|
'session', 'rename', { request: request.payload }, signal,
|
|
253
254
|
)),
|
|
255
|
+
fork: (request, signal) => rpcResult(request, () => this.#invoke(
|
|
256
|
+
'session', 'fork', { request: request.payload }, signal,
|
|
257
|
+
)),
|
|
254
258
|
cancel: (request, signal) => rpcResult(request, () => this.#invoke(
|
|
255
259
|
'session', 'cancel', { request: { sessionId: request.payload.sessionId } }, signal,
|
|
256
260
|
)),
|
|
@@ -958,7 +962,7 @@ class ModernHarnessApi {
|
|
|
958
962
|
|
|
959
963
|
/** Create one modern compatibility API per Cordis Host root. */
|
|
960
964
|
export function modernHarnessApi(ctx, { deliveryService } = {}) {
|
|
961
|
-
const scope = ctx
|
|
965
|
+
const scope = rootScope(ctx);
|
|
962
966
|
if (!scope || !['object', 'function'].includes(typeof scope)) {
|
|
963
967
|
throw new TypeError('dsh-im requires a Cordis Host context');
|
|
964
968
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The application's root Cordis context.
|
|
3
|
+
*
|
|
4
|
+
* `root` used to be an ordinary property of every context. Cordis 4.2 moved it
|
|
5
|
+
* onto the symbol key `Symbol.for('cordis.root')` and made a plain `ctx.root`
|
|
6
|
+
* read throw `cannot get property "root" without inject`, so every caller that
|
|
7
|
+
* treated it as a property now dies at activation time.
|
|
8
|
+
*
|
|
9
|
+
* The symbol read is legal on both versions: 4.1 already installs the same
|
|
10
|
+
* symbol on every context, 4.2 keeps the property behind a guard. Reading the
|
|
11
|
+
* property stays as a fallback for hosts that predate the symbol.
|
|
12
|
+
*/
|
|
13
|
+
const ROOT_SYMBOL = Symbol.for('cordis.root');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Resolve the root context of `ctx`, falling back to `ctx` itself.
|
|
17
|
+
* @param ctx - any Cordis context, possibly undefined.
|
|
18
|
+
* @returns the root context, or `ctx` when no root can be read.
|
|
19
|
+
*/
|
|
20
|
+
export function rootScope(ctx) {
|
|
21
|
+
try {
|
|
22
|
+
const root = ctx?.[ROOT_SYMBOL];
|
|
23
|
+
if (root) return root;
|
|
24
|
+
} catch {
|
|
25
|
+
// A context that refuses symbol reads still accepts the property below.
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
return ctx?.root ?? ctx;
|
|
29
|
+
} catch {
|
|
30
|
+
return ctx;
|
|
31
|
+
}
|
|
32
|
+
}
|