@xmanrui/dsh-im 5.10.0 → 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/README.en.md +39 -5
- package/README.md +42 -5
- package/bin/dsh-im.mjs +65 -0
- package/docs/client-integration.md +4 -0
- package/lib/client.js +1202 -95
- package/lib/index.js +365 -339
- 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/i18n-ru.js +85 -0
- package/plugin-src/client/i18n.js +83 -0
- package/plugin-src/client/im-channels.js +419 -0
- package/plugin-src/client/index.js +33 -1
- package/plugin-src/client/styles.js +7 -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 +39 -10
- 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/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-service.mjs +3 -4
- package/plugin-src/host/delivery-suggestions.mjs +3 -1
- package/plugin-src/host/harness-connection.mjs +2 -1
- package/plugin-src/host/harness-peer.mjs +3 -1
- package/plugin-src/host/index.mjs +8 -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 +2 -1
- package/plugin-src/management-rpc.mjs +18 -2
- package/scripts/verify-package.mjs +36 -7
- 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 +105 -14
- package/src/channels/qq/state-store.mjs +13 -1
- package/src/channels/shared/access-policy.mjs +60 -7
- package/src/channels/shared/bot-workspace-store.mjs +155 -3
- 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/diagnostic-details.mjs +6 -1
- package/src/channels/shared/failure-log-file.mjs +79 -0
- package/src/channels/shared/harness-client.mjs +111 -6
- 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 +67 -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/feishu.mjs +2 -2
- package/src/channels/shared/i18n-ru/shared-a.mjs +13 -2
- package/src/channels/shared/i18n-ru/shared-b.mjs +67 -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/markdown-chunks.mjs +5 -0
- package/src/channels/shared/message-failure.mjs +22 -1
- 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 +39 -3
- package/src/channels/slack/slack-api.mjs +2 -1
- package/src/channels/telegram/config-store.mjs +10 -2
- 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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SET_MESSAGE_MODE_ENDPOINT, validMessageModePayload } from '../../../../src/channels/shared/message-mode.mjs';
|
|
2
|
+
import { SET_REPLY_CONTENT_ENDPOINT, validReplyContentPayload } from '../shared/reply-content-rpc.mjs';
|
|
2
3
|
import { createConnectionDiagnostics, diagnosticRpcResult } from '../../../../src/channels/shared/connection-error.mjs';
|
|
3
4
|
import { SET_ALIAS_ENDPOINT, validAliasPayload } from '../shared/bot-alias-rpc.mjs';
|
|
4
5
|
import { registerManagementRpc } from '../../../management-rpc.mjs';
|
|
@@ -26,6 +27,7 @@ export const WECOM_APP_ENDPOINTS = Object.freeze({
|
|
|
26
27
|
setAgentPreset: SET_AGENT_PRESET_ENDPOINT,
|
|
27
28
|
setContextEnhancement: SET_CONTEXT_ENHANCEMENT_ENDPOINT,
|
|
28
29
|
setBusyMessageMode: SET_MESSAGE_MODE_ENDPOINT,
|
|
30
|
+
setReplyContent: SET_REPLY_CONTENT_ENDPOINT,
|
|
29
31
|
setAccessPolicy: SET_ACCESS_POLICY_ENDPOINT,
|
|
30
32
|
setAlias: SET_ALIAS_ENDPOINT,
|
|
31
33
|
});
|
|
@@ -112,6 +114,10 @@ function payloadFailure(endpoint, payload) {
|
|
|
112
114
|
if (endpoint === WECOM_APP_ENDPOINTS.setAgentPreset) {
|
|
113
115
|
return validAgentPresetPayload(payload) ? null : '请选择 Agent Preset。';
|
|
114
116
|
}
|
|
117
|
+
if (endpoint === WECOM_APP_ENDPOINTS.setReplyContent) {
|
|
118
|
+
return validReplyContentPayload(payload)
|
|
119
|
+
? null : '请选择要投递的回复内容。';
|
|
120
|
+
}
|
|
115
121
|
if (endpoint === WECOM_APP_ENDPOINTS.setBusyMessageMode) {
|
|
116
122
|
return validMessageModePayload(payload) ? null : '请提交有效的消息处理方式。';
|
|
117
123
|
}
|
|
@@ -196,6 +202,9 @@ export function createWecomAppRpcHandler(controller) {
|
|
|
196
202
|
} else if (endpoint === WECOM_APP_ENDPOINTS.setModel) {
|
|
197
203
|
if (typeof controller.updateModel !== 'function') throw new Error('Model update is unavailable');
|
|
198
204
|
value = await publicStatus(await controller.updateModel(payload.botId, payload.model));
|
|
205
|
+
} else if (endpoint === WECOM_APP_ENDPOINTS.setReplyContent) {
|
|
206
|
+
if (typeof controller.updateReplyContent !== 'function') throw new Error('Reply content update is unavailable');
|
|
207
|
+
value = await controller.updateReplyContent(payload.botId, payload.replyContent);
|
|
199
208
|
} else if (endpoint === WECOM_APP_ENDPOINTS.setBusyMessageMode) {
|
|
200
209
|
if (typeof controller.updateBusyMessageMode !== 'function') throw new Error('Message mode update is unavailable');
|
|
201
210
|
value = await controller.updateBusyMessageMode(
|
|
@@ -24,6 +24,7 @@ import { prepareBotWorkspace } from '../../../../src/channels/shared/default-wor
|
|
|
24
24
|
import { listAgentPresetCatalog } from '../../../../src/channels/shared/agent-preset.mjs';
|
|
25
25
|
import { listModelCatalog } from '../../../../src/channels/shared/model-setting.mjs';
|
|
26
26
|
import { createDeliveryAdapter } from '../../delivery-adapter.mjs';
|
|
27
|
+
import { createAnnouncedStateStore, createBindingAnnouncer } from '../shared/binding-events.mjs';
|
|
27
28
|
import { createConnectionSupervisor } from './connection-supervisor.mjs';
|
|
28
29
|
import { createHarnessCommandExecutor } from '../../harness-command-executor.mjs';
|
|
29
30
|
import { harnessConnection } from '../../harness-connection.mjs';
|
|
@@ -116,14 +117,29 @@ export async function createProductionController(ctx, config = {}, internals = {
|
|
|
116
117
|
const stateStores = new Map();
|
|
117
118
|
|
|
118
119
|
const statePath = (botId) => resolve(paths.accounts, botId, 'state.json');
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Every binding change is announced the moment it is written: a bind before the
|
|
122
|
+
* Session exists, an unbind when the conversation moves to another session or
|
|
123
|
+
* its binding is cleared. Listeners run synchronously.
|
|
124
|
+
*/
|
|
125
|
+
const announcer = createBindingAnnouncer({
|
|
126
|
+
channel: 'weixin',
|
|
127
|
+
emit: (event, payload) => ctx.emit(event, payload),
|
|
128
|
+
authorsOf: (botId) => (typeof stateStores.get(botId)?.snapshot === 'function'
|
|
129
|
+
? stateStores.get(botId).snapshot()?.authors ?? null
|
|
130
|
+
: null),
|
|
131
|
+
});
|
|
132
|
+
const { stateFor, stateForSync, prime, forget } = createAnnouncedStateStore({
|
|
133
|
+
announcer,
|
|
134
|
+
StateStore,
|
|
135
|
+
statePath,
|
|
136
|
+
states: stateStores,
|
|
137
|
+
logger,
|
|
138
|
+
});
|
|
139
|
+
// Warm the per-bot state memo now: the synchronous identity lookup can only
|
|
140
|
+
// answer from state that is already loaded in this process, and the first prompt
|
|
141
|
+
// of a session arrives long before any delivery call would load it.
|
|
142
|
+
await prime(configuredBots.map((bot) => bot.botId));
|
|
127
143
|
const commandExecutor = createHarnessCommandExecutor(ctx, internals.commandExecutor);
|
|
128
144
|
const inboundTtl = internals.inboundTtl ?? getInboundTtlRuntime(ctx, config);
|
|
129
145
|
const inboundTtlService = inboundTtl?.service ?? inboundTtl;
|
|
@@ -189,8 +205,8 @@ export async function createProductionController(ctx, config = {}, internals = {
|
|
|
189
205
|
});
|
|
190
206
|
},
|
|
191
207
|
deleteState: async ({ botId }) => {
|
|
192
|
-
const state =
|
|
193
|
-
|
|
208
|
+
const state = stateForSync(botId);
|
|
209
|
+
forget(botId);
|
|
194
210
|
if (state && typeof state.remove === 'function') {
|
|
195
211
|
await state.remove();
|
|
196
212
|
} else {
|
|
@@ -239,6 +255,8 @@ export async function createProductionController(ctx, config = {}, internals = {
|
|
|
239
255
|
controller,
|
|
240
256
|
deliveryAdapter: createDeliveryAdapter({ dsBot: config.deliveryService?.dsBot,
|
|
241
257
|
channel: 'weixin', workspaces, coreController, stateFor,
|
|
258
|
+
// The same store, without the await: it is a memo of already loaded bots.
|
|
259
|
+
stateForSync,
|
|
242
260
|
}),
|
|
243
261
|
ready: supervisor.ready,
|
|
244
262
|
async close() {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SET_MESSAGE_MODE_ENDPOINT, validMessageModePayload } from '../../../../src/channels/shared/message-mode.mjs';
|
|
2
|
+
import { SET_REPLY_CONTENT_ENDPOINT, validReplyContentPayload } from '../shared/reply-content-rpc.mjs';
|
|
2
3
|
import { SET_ALIAS_ENDPOINT, validAliasPayload } from '../shared/bot-alias-rpc.mjs';
|
|
3
4
|
import { registerManagementRpc } from '../../../management-rpc.mjs';
|
|
4
|
-
import QRCode from 'qrcode';
|
|
5
|
+
import QRCode from '../../../../src/channels/shared/qrcode.mjs';
|
|
5
6
|
import { qrEncodingError } from '../../../../src/channels/shared/qr-encoding-error.mjs';
|
|
6
7
|
import { createWeixinDiagnostics, weixinStageError } from '../../../../src/channels/weixin/connection-error.mjs';
|
|
7
8
|
import { SET_CONTEXT_ENHANCEMENT_ENDPOINT, validContextEnhancementPayload } from '../shared/context-enhancement-rpc.mjs';
|
|
@@ -35,6 +36,7 @@ export const WEIXIN_ENDPOINTS = Object.freeze({
|
|
|
35
36
|
setAgentPreset: SET_AGENT_PRESET_ENDPOINT,
|
|
36
37
|
setContextEnhancement: SET_CONTEXT_ENHANCEMENT_ENDPOINT,
|
|
37
38
|
setBusyMessageMode: SET_MESSAGE_MODE_ENDPOINT,
|
|
39
|
+
setReplyContent: SET_REPLY_CONTENT_ENDPOINT,
|
|
38
40
|
setAccessPolicy: SET_ACCESS_POLICY_ENDPOINT,
|
|
39
41
|
setAlias: SET_ALIAS_ENDPOINT,
|
|
40
42
|
});
|
|
@@ -98,6 +100,10 @@ function payloadFailure(endpoint, payload) {
|
|
|
98
100
|
return validAgentPresetPayload(payload)
|
|
99
101
|
? null : '请选择 Agent Preset。';
|
|
100
102
|
}
|
|
103
|
+
if (endpoint === WEIXIN_ENDPOINTS.setReplyContent) {
|
|
104
|
+
return validReplyContentPayload(payload)
|
|
105
|
+
? null : '请选择要投递的回复内容。';
|
|
106
|
+
}
|
|
101
107
|
if (endpoint === WEIXIN_ENDPOINTS.setBusyMessageMode) {
|
|
102
108
|
return validMessageModePayload(payload)
|
|
103
109
|
? null : '请提交有效的消息处理方式。';
|
|
@@ -242,6 +248,9 @@ export function createWeixinRpcHandler(controller, { encodeQr = qrDataUrl, logge
|
|
|
242
248
|
await controller.updateModel(payload.botId, payload.model),
|
|
243
249
|
cachedEncode,
|
|
244
250
|
);
|
|
251
|
+
} else if (endpoint === WEIXIN_ENDPOINTS.setReplyContent) {
|
|
252
|
+
if (typeof controller.updateReplyContent !== 'function') throw new Error('Reply content update is unavailable');
|
|
253
|
+
value = await controller.updateReplyContent(payload.botId, payload.replyContent);
|
|
245
254
|
} else if (endpoint === WEIXIN_ENDPOINTS.setBusyMessageMode) {
|
|
246
255
|
if (typeof controller.updateBusyMessageMode !== 'function') throw new Error('Message mode update is unavailable');
|
|
247
256
|
value = await controller.updateBusyMessageMode(
|
|
@@ -23,6 +23,7 @@ import { prepareBotWorkspace } from '../../../../src/channels/shared/default-wor
|
|
|
23
23
|
import { listAgentPresetCatalog } from '../../../../src/channels/shared/agent-preset.mjs';
|
|
24
24
|
import { listModelCatalog } from '../../../../src/channels/shared/model-setting.mjs';
|
|
25
25
|
import { createDeliveryAdapter } from '../../delivery-adapter.mjs';
|
|
26
|
+
import { createAnnouncedStateStore, createBindingAnnouncer } from '../shared/binding-events.mjs';
|
|
26
27
|
import { createTokenConnectionSupervisor } from '../shared/connection-supervisor.mjs';
|
|
27
28
|
import { createHarnessCommandExecutor } from '../../harness-command-executor.mjs';
|
|
28
29
|
import { harnessConnection } from '../../harness-connection.mjs';
|
|
@@ -83,14 +84,29 @@ export async function createProductionController(ctx, config = {}, internals = {
|
|
|
83
84
|
: configStore;
|
|
84
85
|
const stateStores = new Map();
|
|
85
86
|
const statePath = (botId) => resolve(paths.bots, botId, 'state.json');
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Every binding change is announced the moment it is written: a bind before the
|
|
89
|
+
* Session exists, an unbind when the conversation moves to another session or
|
|
90
|
+
* its binding is cleared. Listeners run synchronously.
|
|
91
|
+
*/
|
|
92
|
+
const announcer = createBindingAnnouncer({
|
|
93
|
+
channel: 'whatsapp',
|
|
94
|
+
emit: (event, payload) => ctx.emit(event, payload),
|
|
95
|
+
authorsOf: (botId) => (typeof stateStores.get(botId)?.snapshot === 'function'
|
|
96
|
+
? stateStores.get(botId).snapshot()?.authors ?? null
|
|
97
|
+
: null),
|
|
98
|
+
});
|
|
99
|
+
const { stateFor, stateForSync, prime, forget } = createAnnouncedStateStore({
|
|
100
|
+
announcer,
|
|
101
|
+
StateStore,
|
|
102
|
+
statePath,
|
|
103
|
+
states: stateStores,
|
|
104
|
+
logger,
|
|
105
|
+
});
|
|
106
|
+
// Warm the per-bot state memo now: the synchronous identity lookup can only
|
|
107
|
+
// answer from state that is already loaded in this process, and the first prompt
|
|
108
|
+
// of a session arrives long before any delivery call would load it.
|
|
109
|
+
await prime(configuredBots.map((bot) => bot.botId));
|
|
94
110
|
const commandExecutor = createHarnessCommandExecutor(ctx, internals.commandExecutor);
|
|
95
111
|
const inboundTtl = internals.inboundTtl ?? getInboundTtlRuntime(ctx, config);
|
|
96
112
|
const inboundTtlService = inboundTtl?.service ?? inboundTtl;
|
|
@@ -159,8 +175,8 @@ export async function createProductionController(ctx, config = {}, internals = {
|
|
|
159
175
|
force: true,
|
|
160
176
|
}),
|
|
161
177
|
deleteState: async ({ botId }) => {
|
|
162
|
-
const state =
|
|
163
|
-
|
|
178
|
+
const state = stateForSync(botId);
|
|
179
|
+
forget(botId);
|
|
164
180
|
if (state && typeof state.remove === 'function') {
|
|
165
181
|
await state.remove();
|
|
166
182
|
} else {
|
|
@@ -191,6 +207,8 @@ export async function createProductionController(ctx, config = {}, internals = {
|
|
|
191
207
|
controller,
|
|
192
208
|
deliveryAdapter: createDeliveryAdapter({ dsBot: config.deliveryService?.dsBot,
|
|
193
209
|
channel: 'whatsapp', workspaces, coreController, stateFor,
|
|
210
|
+
// The same store, without the await: it is a memo of already loaded bots.
|
|
211
|
+
stateForSync,
|
|
194
212
|
}),
|
|
195
213
|
ready: supervisor.ready,
|
|
196
214
|
async close() {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { SET_MESSAGE_MODE_ENDPOINT, validMessageModePayload } from '../../../../src/channels/shared/message-mode.mjs';
|
|
2
|
+
import { SET_REPLY_CONTENT_ENDPOINT, validReplyContentPayload } from '../shared/reply-content-rpc.mjs';
|
|
2
3
|
import { createConnectionDiagnostics, diagnosticRpcResult } from '../../../../src/channels/shared/connection-error.mjs';
|
|
3
4
|
import { SET_ALIAS_ENDPOINT, validAliasPayload } from '../shared/bot-alias-rpc.mjs';
|
|
4
5
|
import { registerManagementRpc } from '../../../management-rpc.mjs';
|
|
5
|
-
import QRCode from 'qrcode';
|
|
6
|
+
import QRCode from '../../../../src/channels/shared/qrcode.mjs';
|
|
6
7
|
import { qrEncodingError } from '../../../../src/channels/shared/qr-encoding-error.mjs';
|
|
7
8
|
|
|
8
9
|
import { publicConnectionTestResult } from '../../../../src/channels/shared/connection-test.mjs';
|
|
@@ -28,6 +29,7 @@ export const WHATSAPP_ENDPOINTS = Object.freeze({
|
|
|
28
29
|
setAgentPreset: SET_AGENT_PRESET_ENDPOINT,
|
|
29
30
|
setContextEnhancement: SET_CONTEXT_ENHANCEMENT_ENDPOINT,
|
|
30
31
|
setBusyMessageMode: SET_MESSAGE_MODE_ENDPOINT,
|
|
32
|
+
setReplyContent: SET_REPLY_CONTENT_ENDPOINT,
|
|
31
33
|
});
|
|
32
34
|
export const WHATSAPP_RPC_ENDPOINTS = Object.freeze(Object.values(WHATSAPP_ENDPOINTS));
|
|
33
35
|
|
|
@@ -82,6 +84,10 @@ function payloadFailure(endpoint, payload) {
|
|
|
82
84
|
return validAgentPresetPayload(payload)
|
|
83
85
|
? null : '请选择 Agent Preset。';
|
|
84
86
|
}
|
|
87
|
+
if (endpoint === WHATSAPP_ENDPOINTS.setReplyContent) {
|
|
88
|
+
return validReplyContentPayload(payload)
|
|
89
|
+
? null : '请选择要投递的回复内容。';
|
|
90
|
+
}
|
|
85
91
|
if (endpoint === WHATSAPP_ENDPOINTS.setBusyMessageMode) {
|
|
86
92
|
return validMessageModePayload(payload)
|
|
87
93
|
? null : '请提交有效的消息处理方式。';
|
|
@@ -202,6 +208,9 @@ export function createWhatsappRpcHandler(controller, { encodeQr = qrDataUrl } =
|
|
|
202
208
|
await controller.updateModel(payload.botId, payload.model),
|
|
203
209
|
cachedEncode,
|
|
204
210
|
);
|
|
211
|
+
} else if (endpoint === WHATSAPP_ENDPOINTS.setReplyContent) {
|
|
212
|
+
if (typeof controller.updateReplyContent !== 'function') throw new Error('Reply content update is unavailable');
|
|
213
|
+
value = await controller.updateReplyContent(payload.botId, payload.replyContent);
|
|
205
214
|
} else if (endpoint === WHATSAPP_ENDPOINTS.setBusyMessageMode) {
|
|
206
215
|
if (typeof controller.updateBusyMessageMode !== 'function') throw new Error('Message mode update is unavailable');
|
|
207
216
|
value = await controller.updateBusyMessageMode(
|
|
@@ -595,10 +595,9 @@ export class DeliveryService {
|
|
|
595
595
|
}
|
|
596
596
|
const draft = deliverySuggestionFromConversationKey(described.channel, described.conversationKey);
|
|
597
597
|
if (!draft) {
|
|
598
|
-
// A key the channel persisted but no route covers stays unroutable.
|
|
599
|
-
//
|
|
600
|
-
//
|
|
601
|
-
// message the wrong place, so the key is only reported here.
|
|
598
|
+
// A key the channel persisted but no route covers stays unroutable.
|
|
599
|
+
// Do not guess a parent chat for an unrecognized key: that would drop a
|
|
600
|
+
// thread id and message the wrong place.
|
|
602
601
|
this.#warnUndelivered(sessionId, 'unroutable', described);
|
|
603
602
|
return { sent: false, reason: 'unroutable' };
|
|
604
603
|
}
|
|
@@ -62,12 +62,14 @@ function slackSuggestion(key) {
|
|
|
62
62
|
|
|
63
63
|
// Telegram-only: numeric chat/topic keys can safely prefill Telegram target fields.
|
|
64
64
|
// Other channels must use their native route fields; never turn their keys into Telegram links.
|
|
65
|
+
// A private chat with Topics persists `direct:<chatId>:<threadId>` (the same
|
|
66
|
+
// message_thread_id a forum topic uses). Route that as a topic. Treating it as
|
|
67
|
+
// a plain chat, or as unroutable, either drops the thread or never delivers.
|
|
65
68
|
function telegramSuggestion(key) {
|
|
66
69
|
const match = /^(direct|group):(-?\d+)(?::([1-9]\d*))?$/.exec(key);
|
|
67
70
|
if (!match) return null;
|
|
68
71
|
const chatId = Number(match[2]);
|
|
69
72
|
if (!Number.isSafeInteger(chatId)) return null;
|
|
70
|
-
if (match[1] === 'direct' && match[3] !== undefined) return null;
|
|
71
73
|
if (match[3] === undefined) return { kind: 'chat', route: { chatId: match[2] } };
|
|
72
74
|
const messageThreadId = Number(match[3]);
|
|
73
75
|
if (!Number.isSafeInteger(messageThreadId) || messageThreadId <= 0) return null;
|
|
@@ -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;
|
|
@@ -30,6 +30,8 @@ import { deliverySwitchesOff } from '../../src/channels/shared/delivery-sync-set
|
|
|
30
30
|
import { getDeliverySyncSettingsStore } from '../../src/channels/shared/delivery-sync-settings-store.mjs';
|
|
31
31
|
import { installSessionTitlePrefix } from './session-title-prefix.mjs';
|
|
32
32
|
import { installUpdateRpc } from './update-rpc.mjs';
|
|
33
|
+
import { installChannelListRpc } from './channel-list-rpc.mjs';
|
|
34
|
+
import { rootScope } from './root-scope.mjs';
|
|
33
35
|
|
|
34
36
|
export const name = 'dsh-im-host';
|
|
35
37
|
export const inject = [
|
|
@@ -242,6 +244,11 @@ export function createImHostPlugin(internals = {}) {
|
|
|
242
244
|
} catch (error) {
|
|
243
245
|
logger.error?.('[dsh-im] failed to activate delivery management; continuing with channels', error);
|
|
244
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
|
+
}
|
|
245
252
|
}
|
|
246
253
|
const failures = [];
|
|
247
254
|
// Each channel mounts its management RPC before awaiting initialization.
|
|
@@ -261,7 +268,7 @@ export function createImHostPlugin(internals = {}) {
|
|
|
261
268
|
try {
|
|
262
269
|
startSessionSync(ctx, deliveryService, {
|
|
263
270
|
logger,
|
|
264
|
-
inputScope: ctx
|
|
271
|
+
inputScope: rootScope(ctx),
|
|
265
272
|
config,
|
|
266
273
|
});
|
|
267
274
|
installDsBotQuestionSync(ctx, deliveryService, { logger });
|
|
@@ -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
|
+
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from '../../src/channels/shared/delivery-sync-settings.mjs';
|
|
12
12
|
import { getDeliverySyncSettingsStore } from '../../src/channels/shared/delivery-sync-settings-store.mjs';
|
|
13
13
|
import { deliverSessionSyncMirror } from '../../src/channels/shared/session-sync-registry.mjs';
|
|
14
|
+
import { rootScope } from './root-scope.mjs';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Where the turn came from, as far as a chat mirror is concerned.
|
|
@@ -363,7 +364,7 @@ export function isImOwnedInput(scope, event) {
|
|
|
363
364
|
|
|
364
365
|
export function installSessionSyncCoordinator(ctx, deliveryService, {
|
|
365
366
|
logger = console,
|
|
366
|
-
inputScope = ctx
|
|
367
|
+
inputScope = rootScope(ctx),
|
|
367
368
|
loadSettings = null,
|
|
368
369
|
imInputOwnership = isImOwnedInput,
|
|
369
370
|
config = {},
|
|
@@ -37,14 +37,30 @@ function reply(rpcId, result) {
|
|
|
37
37
|
return Response.json({ type: 'server-response', rpcId, result: value });
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
function resolveFetchRegistry(ctx) {
|
|
41
|
+
// `ctx.connection` may be a Cordis service proxy whose `fetch` is a getter.
|
|
42
|
+
// Reading it once inside try/catch both triggers the getter and tolerates a
|
|
43
|
+
// proxy that has not resolved yet; fall back to an explicitly resolved service.
|
|
44
|
+
const candidates = [];
|
|
45
|
+
try { candidates.push(ctx?.connection); } catch { /* unresolved proxy */ }
|
|
46
|
+
try { candidates.push(ctx?.get?.('connection')); } catch { /* service not ready */ }
|
|
47
|
+
for (const connection of candidates) {
|
|
48
|
+
if (!connection) continue;
|
|
49
|
+
let registry;
|
|
50
|
+
try { registry = connection.fetch; } catch { continue; }
|
|
51
|
+
if (typeof registry?.register === 'function') return registry;
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
40
55
|
/** Register an IM channel through the public /api carrier shared by supported DSH releases. */
|
|
41
56
|
export function registerManagementRpc(ctx, channel, handler, { authority } = {}) {
|
|
42
57
|
const policy = resolveRpcAuthority(authority);
|
|
43
58
|
const endpoint = rpcEndpoint(channel);
|
|
44
|
-
|
|
59
|
+
const registry = resolveFetchRegistry(ctx);
|
|
60
|
+
if (typeof registry?.register !== 'function') {
|
|
45
61
|
throw new TypeError('DSH Host Connection Fetch registry is required');
|
|
46
62
|
}
|
|
47
|
-
return
|
|
63
|
+
return registry.register({
|
|
48
64
|
path: `/api/${endpoint}`,
|
|
49
65
|
methods: ['POST'],
|
|
50
66
|
requestBody: 'buffered',
|
|
@@ -123,6 +123,34 @@ if (forbiddenDshLockPaths.length > 0) {
|
|
|
123
123
|
);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
// The client inject list and the compatibility baseline both name host-side
|
|
127
|
+
// packages and releases that live outside this repository, so a stale entry
|
|
128
|
+
// passes every bundle assertion below while it silently costs the client row its
|
|
129
|
+
// load order (or advertises a baseline the build was never verified against).
|
|
130
|
+
const compatibility = manifest.dsh?.compatibility ?? {};
|
|
131
|
+
const clientInject = manifest.dsh?.client?.inject ?? [];
|
|
132
|
+
if (typeof compatibility.dsh !== 'string'
|
|
133
|
+
|| !/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u.test(compatibility.dsh)
|
|
134
|
+
|| compatibility.dshReleases?.[compatibility.dsh] !== 'compatible') {
|
|
135
|
+
throw new Error('dsh.compatibility.dsh must name a release that dshReleases marks compatible');
|
|
136
|
+
}
|
|
137
|
+
if (clientInject.length === 0 || new Set(clientInject).size !== clientInject.length) {
|
|
138
|
+
throw new Error('dsh.client.inject must list unique DSH client packages');
|
|
139
|
+
}
|
|
140
|
+
for (const name of clientInject) {
|
|
141
|
+
if (!/^@deepseek-ai\/dsh-client-[a-z0-9-]+$/u.test(name)) {
|
|
142
|
+
throw new Error(`dsh.client.inject must name DSH client packages: ${name}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Neither package is a Web client row on DSH 0.2.2-rc.5: the runtime package
|
|
146
|
+
// stopped publishing after 0.1.1-rc.2 and ui-slots is the registry core without
|
|
147
|
+
// a client entry. Injecting them waits for rows that never arrive.
|
|
148
|
+
for (const retired of ['@deepseek-ai/dsh-client-runtime', '@deepseek-ai/dsh-client-ui-slots']) {
|
|
149
|
+
if (clientInject.includes(retired)) {
|
|
150
|
+
throw new Error(`${retired} is not a loadable DSH 0.2.2-rc.5 client row`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
126
154
|
if (!/\bid\s*:\s*["']@xmanrui\/dsh-im["']/u.test(client)) {
|
|
127
155
|
throw new Error('client bundle does not register the dsh-im loader id');
|
|
128
156
|
}
|
|
@@ -153,8 +181,9 @@ if (client.includes('settings.plugins.tab') || clientSources.includes('settings.
|
|
|
153
181
|
// The context editor contains one switch template and one mapped field-input
|
|
154
182
|
// template; the delivery target adds one ordinary checkbox template; the
|
|
155
183
|
// Telegram thinking-traces block adds two ordinary checkbox templates (traces
|
|
156
|
-
// and frame numbering). General settings adds
|
|
157
|
-
// the
|
|
184
|
+
// and frame numbering). General settings adds two mapped switch templates: one
|
|
185
|
+
// for the shared reply-content switches, one for the two Feishu panel
|
|
186
|
+
// preferences. Conversation-directory settings adds one
|
|
158
187
|
// switch template reused for the bot override and channel default. The Delivery
|
|
159
188
|
// tab adds one ordinary checkbox template mapped over its two switches (mirror
|
|
160
189
|
// Web input, deliver model answers).
|
|
@@ -181,15 +210,15 @@ if (/role:\s*["']switch|type:\s*["']checkbox/.test(otherClientSources)
|
|
|
181
210
|
|| /role:\s*["']switch["']/u.test(deliverySettingsSource)
|
|
182
211
|
|| (thinkingTracesSource.match(/type:\s*["']checkbox["']/g) ?? []).length !== 2
|
|
183
212
|
|| /role:\s*["']switch["']/u.test(thinkingTracesSource)
|
|
184
|
-
|| (botGeneralSettingsSource.match(/type:\s*["']checkbox["']/g) ?? []).length !==
|
|
185
|
-
|| (botGeneralSettingsSource.match(/role:\s*["']switch["']/g) ?? []).length !==
|
|
213
|
+
|| (botGeneralSettingsSource.match(/type:\s*["']checkbox["']/g) ?? []).length !== 2
|
|
214
|
+
|| (botGeneralSettingsSource.match(/role:\s*["']switch["']/g) ?? []).length !== 2
|
|
186
215
|
|| (conversationDirectorySettingsSource.match(/type:\s*["']checkbox["']/g) ?? []).length !== 1
|
|
187
216
|
|| (conversationDirectorySettingsSource.match(/role:\s*["']switch["']/g) ?? []).length !== 1
|
|
188
217
|
|| (deliverySyncSettingsSource.match(/type:\s*["']checkbox["']/g) ?? []).length !== 1
|
|
189
218
|
|| /role:\s*["']switch["']/u.test(deliverySyncSettingsSource)
|
|
190
|
-
|| (client.match(/role:\s*["']switch["']/g) ?? []).length !==
|
|
191
|
-
|| (client.match(/type:\s*["']checkbox["']/g) ?? []).length !==
|
|
192
|
-
throw new Error('checkable inputs must be limited to context enhancement, Session sync, email settings, Telegram thinking traces, Feishu panel settings, conversation-directory settings, and the Delivery tab');
|
|
219
|
+
|| (client.match(/role:\s*["']switch["']/g) ?? []).length !== 4
|
|
220
|
+
|| (client.match(/type:\s*["']checkbox["']/g) ?? []).length !== 9) {
|
|
221
|
+
throw new Error('checkable inputs must be limited to context enhancement, Session sync, email settings, Telegram thinking traces, Feishu panel settings, reply content, conversation-directory settings, and the Delivery tab');
|
|
193
222
|
}
|
|
194
223
|
for (const marker of ['bot.conversation-directory.set', 'bot.conversation-directory.default.set']) {
|
|
195
224
|
if (!host.includes(marker) || !client.includes(marker)) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BusyMessageDispatcher, canAutomaticallySteer } from '../shared/busy-message-dispatcher.mjs';
|
|
2
|
+
import { SESSION_NAV_HELP_LINES } from '../shared/command-catalog.mjs';
|
|
2
3
|
import { createDeferredDeliveryCoordinator, deferredOutcomeText } from '../shared/deferred-delivery-coordinator.mjs';
|
|
3
4
|
import {
|
|
4
5
|
DINGTALK_DONE_REACTION_NAME,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
import { HarnessApprovalQueue } from '../shared/harness-approval.mjs';
|
|
18
19
|
import { runCompactCommand } from '../shared/compact-command.mjs';
|
|
19
20
|
import { isClearCommand, runClearCommand } from '../shared/clear-command.mjs';
|
|
21
|
+
import { isResetCommand, runResetCommand } from '../shared/reset-command.mjs';
|
|
20
22
|
import { isHistoryCommand, runHistoryCommand } from '../shared/history-command.mjs';
|
|
21
23
|
import {
|
|
22
24
|
isControlCommand,
|
|
@@ -32,6 +34,11 @@ import {
|
|
|
32
34
|
} from '../shared/preset-command.mjs';
|
|
33
35
|
import { conversationSessionWorkspace, runWorkspaceCommand } from '../shared/workspace-command.mjs';
|
|
34
36
|
import { askInWorkspaceSession } from '../shared/workspace-session.mjs';
|
|
37
|
+
import {
|
|
38
|
+
isSessionNavCommand,
|
|
39
|
+
runSessionNavTextCommand,
|
|
40
|
+
} from '../shared/session-nav-command.mjs';
|
|
41
|
+
import { createConversationSession, isNewCommand, newCommandTitle } from '../shared/new-command.mjs';
|
|
35
42
|
import {
|
|
36
43
|
captureContextEnhancement,
|
|
37
44
|
captureContextEnhancementSource,
|
|
@@ -95,8 +102,10 @@ const HELP_TEXT_LINES = [
|
|
|
95
102
|
'/workspacelist 列出工作区绝对路径',
|
|
96
103
|
'/ws、/wsl、/workspaces 工作区命令别名',
|
|
97
104
|
'/sessionlist 或 /sessions [工作区序号或绝对路径] 列出会话 ID 和标题',
|
|
105
|
+
'/sessionlist --all 跨工作区汇总会话(每个工作区默认显示 10 个,可用 --limit N 调整)',
|
|
98
106
|
'/sessionlist --limit N 仅列出当前工作区前 N 个会话',
|
|
99
|
-
'/session Session ID
|
|
107
|
+
'/session Session ID、当前工作区序号或标题关键词 将当前聊天绑定到指定会话',
|
|
108
|
+
...SESSION_NAV_HELP_LINES,
|
|
100
109
|
'/models 按序号列出所有可用模型',
|
|
101
110
|
'/reasoninglist 或 /reasonings 按序号列出当前模型可用推理等级',
|
|
102
111
|
'/reasoning [序号、等级ID或 --default] 查看或切换当前推理等级',
|
|
@@ -721,6 +730,7 @@ export class DingtalkHarnessBridge {
|
|
|
721
730
|
&& !hasInboundFiles(promptMessage) && !hasInboundImages(promptMessage)
|
|
722
731
|
? async () => { await this.#showMenu(message, key); }
|
|
723
732
|
: isClearCommand(commandText) ? runClearCommand
|
|
733
|
+
: isResetCommand(commandText) ? runResetCommand
|
|
724
734
|
: isHistoryCommand(commandText) ? runHistoryCommand
|
|
725
735
|
: hasInboundFiles(promptMessage) ? null : isControlCommand(commandText)
|
|
726
736
|
? runControlCommand
|
|
@@ -949,8 +959,8 @@ export class DingtalkHarnessBridge {
|
|
|
949
959
|
&& !['/stop', '/help', '/status', '/history'].includes(command)) {
|
|
950
960
|
result = { message: t('当前任务尚未结束,请先停止任务或等待完成后再操作。') };
|
|
951
961
|
} else if (command === '/new') {
|
|
952
|
-
await this.#state
|
|
953
|
-
result = { message: t('已开启新会话。请发送你的问题。') };
|
|
962
|
+
const created = await createConversationSession({ state: this.#state, harness: this.#harness, key });
|
|
963
|
+
result = { message: created.failed ? t('暂时无法创建新会话,请稍后重试。') : t('已开启新会话。请发送你的问题。') };
|
|
954
964
|
} else if (command === '/status') {
|
|
955
965
|
await this.#harness.ensureRunning({ signal: this.#signal });
|
|
956
966
|
result = { message: t('钉钉机器人与 DeepSeek Harness 连接正常。') };
|
|
@@ -959,6 +969,7 @@ export class DingtalkHarnessBridge {
|
|
|
959
969
|
} else {
|
|
960
970
|
result = await runWorkspaceCommand(command, this.#harness, key)
|
|
961
971
|
?? await runClearCommand(command, this.#harness, this.#state, key, options)
|
|
972
|
+
?? await runResetCommand(command, this.#harness, this.#state, key, options)
|
|
962
973
|
?? await runCompactCommand(command, this.#harness, this.#state, key, options)
|
|
963
974
|
?? await runControlCommand(command, this.#harness, this.#state, key, options)
|
|
964
975
|
?? await runHistoryCommand(command, this.#harness, this.#state, key, options)
|
|
@@ -1334,9 +1345,33 @@ export class DingtalkHarnessBridge {
|
|
|
1334
1345
|
await this.#send(sessionWebhook, t('钉钉机器人与 DeepSeek Harness 连接正常。'), this.#atUsersFor(message));
|
|
1335
1346
|
return;
|
|
1336
1347
|
}
|
|
1337
|
-
if (isPlainText && !hasImages && !hasFiles &&
|
|
1338
|
-
await this.#state
|
|
1339
|
-
await this.#send(sessionWebhook, t('已开启新会话。请发送你的问题。'), this.#atUsersFor(message));
|
|
1348
|
+
if (isPlainText && !hasImages && !hasFiles && isNewCommand(text)) {
|
|
1349
|
+
const created = await createConversationSession({ state: this.#state, harness: this.#harness, key, title: newCommandTitle(text) });
|
|
1350
|
+
await this.#send(sessionWebhook, created.failed ? t('暂时无法创建新会话,请稍后重试。') : t('已开启新会话。请发送你的问题。'), this.#atUsersFor(message));
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
if (isPlainText && !hasImages && !hasFiles && isSessionNavCommand(text)) {
|
|
1354
|
+
const nav = await runSessionNavTextCommand(text, this.#harness, this.#state, key, {
|
|
1355
|
+
signal: this.#signal,
|
|
1356
|
+
});
|
|
1357
|
+
if (nav) {
|
|
1358
|
+
for (const reply of nav.messages ?? [nav.message]) {
|
|
1359
|
+
await this.#send(sessionWebhook, reply, this.#atUsersFor(message));
|
|
1360
|
+
}
|
|
1361
|
+
if (nav.askText) {
|
|
1362
|
+
const followUp = this.#enqueueMessage(
|
|
1363
|
+
{ ...message, msgtype: 'text', text: { content: nav.askText } },
|
|
1364
|
+
`${messageId}-ask`,
|
|
1365
|
+
sender,
|
|
1366
|
+
key,
|
|
1367
|
+
{ statusReaction },
|
|
1368
|
+
);
|
|
1369
|
+
followUp.catch((error) => {
|
|
1370
|
+
this.#logger.warn?.(`[dsh-im:dingtalk] follow-up ask after a nav command failed:`, error?.message ?? error);
|
|
1371
|
+
this.#send(sessionWebhook, t('切换后的提问发送失败,请重试。'), this.#atUsersFor(message)).catch(() => undefined);
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1340
1375
|
return;
|
|
1341
1376
|
}
|
|
1342
1377
|
const workspaceCommand = isPlainText && !hasImages && !hasFiles
|
|
@@ -1397,6 +1432,15 @@ export class DingtalkHarnessBridge {
|
|
|
1397
1432
|
cardStarted = await cardStream.start(t(CARD_INITIAL_TEXT));
|
|
1398
1433
|
if (cardStarted) cardStartedAt = startedAt;
|
|
1399
1434
|
}
|
|
1435
|
+
try {
|
|
1436
|
+
await this.#state.rememberAuthor?.(key, {
|
|
1437
|
+
senderId: sender,
|
|
1438
|
+
senderName: message.senderNick,
|
|
1439
|
+
isBot: message.senderIsBot === true,
|
|
1440
|
+
});
|
|
1441
|
+
} catch (error) {
|
|
1442
|
+
this.#logger.warn?.('[dsh-dingtalk] failed to remember the conversation author:', error);
|
|
1443
|
+
}
|
|
1400
1444
|
const { answer, artifacts = [] } = await askInWorkspaceSession({
|
|
1401
1445
|
onNotice: (notice) => this.#send(sessionWebhook, notice, this.#atUsersFor(message)),
|
|
1402
1446
|
deferredDelivery: () => ({ coordinator: this.#deferred, target: { ...cardTarget(message, sender), robotCode: this.#clientId } }),
|