@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,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ring support for the channels that assemble their own state store.
|
|
3
|
+
*
|
|
4
|
+
* The per-conversation navigation ring (`/ls`, `/go`, `/prev`, `/next`, `/drop`,
|
|
5
|
+
* `/title`) lives in `ConversationStateStore`, which the token channels inherit.
|
|
6
|
+
* A channel with its own store has no ring at all, and `workspace-session.mjs`
|
|
7
|
+
* calls `state.ensureSessionRing?.()` optionally - so the binding is written, the
|
|
8
|
+
* ring stays empty, and the chat answers "no sessions in this chat yet".
|
|
9
|
+
*
|
|
10
|
+
* This module is the missing half: the same methods over any live state object,
|
|
11
|
+
* with the same signatures and results as `ConversationStateStore`, plus the
|
|
12
|
+
* normalisation both sides share so the on-disk shape cannot drift.
|
|
13
|
+
*/
|
|
14
|
+
import {
|
|
15
|
+
appendSessionRing,
|
|
16
|
+
createEmptySessionRing,
|
|
17
|
+
dropSessionRingAllExcept,
|
|
18
|
+
dropSessionRingEntry,
|
|
19
|
+
ensureSessionRingEntry,
|
|
20
|
+
markSessionRingEntryUserTitled,
|
|
21
|
+
navigateSessionRing,
|
|
22
|
+
normalizeSessionRing,
|
|
23
|
+
renameSessionRingEntry,
|
|
24
|
+
replaceSessionRingEntry,
|
|
25
|
+
stepSessionRingTo,
|
|
26
|
+
} from './session-ring.mjs';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Rebuild `state.rings` field by field: a conversation key without a usable ring
|
|
30
|
+
* is dropped entirely, so a foreign or corrupt document never becomes a ring the
|
|
31
|
+
* navigation commands would act on.
|
|
32
|
+
*/
|
|
33
|
+
export function normalizeSessionRings(value) {
|
|
34
|
+
const rings = {};
|
|
35
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return rings;
|
|
36
|
+
for (const [key, ring] of Object.entries(value)) {
|
|
37
|
+
if (typeof key !== 'string' || !key) continue;
|
|
38
|
+
const normalized = normalizeSessionRing(ring);
|
|
39
|
+
if (normalized.entries.length > 0 || normalized.visits.length > 0) rings[key] = normalized;
|
|
40
|
+
}
|
|
41
|
+
return rings;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Titles the user set before any Session was bound; empty titles are dropped. */
|
|
45
|
+
export function normalizePendingTitles(value) {
|
|
46
|
+
const titles = {};
|
|
47
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return titles;
|
|
48
|
+
for (const [key, title] of Object.entries(value)) {
|
|
49
|
+
if (typeof key !== 'string' || !key || typeof title !== 'string' || !title.trim()) continue;
|
|
50
|
+
titles[key] = title;
|
|
51
|
+
}
|
|
52
|
+
return titles;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The ring half of a conversation state store.
|
|
57
|
+
*
|
|
58
|
+
* `state` is a getter returning the channel's live state object (the ring is
|
|
59
|
+
* mutated in place), and `persist` is the channel's own writer: every committed
|
|
60
|
+
* change goes through it, and a read (`ringFor`) never writes.
|
|
61
|
+
*
|
|
62
|
+
* @param {{ state: () => object, persist: () => Promise<void> }} options
|
|
63
|
+
*/
|
|
64
|
+
export function createSessionRingSupport({ state, persist } = {}) {
|
|
65
|
+
if (typeof state !== 'function') throw new TypeError('state getter is required');
|
|
66
|
+
if (typeof persist !== 'function') throw new TypeError('persist is required');
|
|
67
|
+
|
|
68
|
+
const ringOf = (key) => state().rings?.[key];
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
/** Read one conversation's ring (a clone; never the live object). */
|
|
72
|
+
ringFor(key) {
|
|
73
|
+
const ring = state().rings?.[key];
|
|
74
|
+
return ring ? structuredClone(ring) : null;
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Record that a Session became bound to this conversation. A Session already
|
|
79
|
+
* in the ring is refreshed; a new one gets the next number. `lastSeenAt` is
|
|
80
|
+
* the Host's last-activity timestamp when known, otherwise the current time.
|
|
81
|
+
* Returns { entry, created }.
|
|
82
|
+
*/
|
|
83
|
+
async ensureSessionRing(key, sessionId, { title, lastSeenAt } = {}) {
|
|
84
|
+
if (typeof key !== 'string' || !key || typeof sessionId !== 'string' || !sessionId) return null;
|
|
85
|
+
const rings = state().rings ??= {};
|
|
86
|
+
const ring = rings[key] ??= createEmptySessionRing();
|
|
87
|
+
const result = ensureSessionRingEntry(ring, sessionId, { title, now: lastSeenAt });
|
|
88
|
+
await persist();
|
|
89
|
+
return result;
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
/** Remove one ring entry by number, leaving a hole. Returns true when dropped. */
|
|
93
|
+
async dropSessionRing(key, n) {
|
|
94
|
+
const ring = ringOf(key);
|
|
95
|
+
if (!ring) return false;
|
|
96
|
+
const removed = dropSessionRingEntry(ring, n);
|
|
97
|
+
if (removed) await persist();
|
|
98
|
+
return removed;
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
/** Remove every ring entry except the one at n. Returns the removed count. */
|
|
102
|
+
async dropSessionRingAllExcept(key, n) {
|
|
103
|
+
const ring = ringOf(key);
|
|
104
|
+
if (!ring) return 0;
|
|
105
|
+
const removed = dropSessionRingAllExcept(ring, n);
|
|
106
|
+
if (removed > 0) await persist();
|
|
107
|
+
return removed;
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
/** Rename one ring entry in place. Returns the updated entry or null. */
|
|
111
|
+
async renameSessionRing(key, n, title) {
|
|
112
|
+
const ring = ringOf(key);
|
|
113
|
+
if (!ring) return null;
|
|
114
|
+
const entry = renameSessionRingEntry(ring, n, title);
|
|
115
|
+
if (entry) await persist();
|
|
116
|
+
return entry ? structuredClone(entry) : null;
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
/** /go navigation: push/jump the visit stack onto entry n. */
|
|
120
|
+
async navigateRing(key, n) {
|
|
121
|
+
const ring = ringOf(key);
|
|
122
|
+
if (!ring) return null;
|
|
123
|
+
navigateSessionRing(ring, n);
|
|
124
|
+
await persist();
|
|
125
|
+
return n;
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
/** Commit a /prev or /next step: point the visit cursor at entry n. */
|
|
129
|
+
async stepRingTo(key, n) {
|
|
130
|
+
const ring = ringOf(key);
|
|
131
|
+
if (!ring) return -1;
|
|
132
|
+
const index = stepSessionRingTo(ring, n);
|
|
133
|
+
await persist();
|
|
134
|
+
return index;
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
/** Append a fallback jump to the visit history without truncating forward. */
|
|
138
|
+
async appendRing(key, n) {
|
|
139
|
+
const ring = ringOf(key);
|
|
140
|
+
if (!ring) return null;
|
|
141
|
+
appendSessionRing(ring, n);
|
|
142
|
+
await persist();
|
|
143
|
+
return n;
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
/** Mark an entry as user-titled so the auto title never overwrites it. */
|
|
147
|
+
async markSessionRingUserTitled(key, n) {
|
|
148
|
+
const ring = ringOf(key);
|
|
149
|
+
if (!ring) return null;
|
|
150
|
+
const entry = markSessionRingEntryUserTitled(ring, n);
|
|
151
|
+
if (entry) await persist();
|
|
152
|
+
return entry ? structuredClone(entry) : null;
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
/** Replace one entry's Session id in place (same number, /reset). */
|
|
156
|
+
async replaceSessionRing(key, n, sessionId, { now } = {}) {
|
|
157
|
+
const ring = ringOf(key);
|
|
158
|
+
if (!ring) return null;
|
|
159
|
+
const entry = replaceSessionRingEntry(ring, n, sessionId, { now });
|
|
160
|
+
if (entry) await persist();
|
|
161
|
+
return entry ? structuredClone(entry) : null;
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
/** Remember a title the user set before a Session was bound yet. */
|
|
165
|
+
async setPendingTitle(key, title) {
|
|
166
|
+
if (typeof key !== 'string' || !key || typeof title !== 'string' || !title.trim()) return null;
|
|
167
|
+
const titles = state().pendingTitles ??= {};
|
|
168
|
+
titles[key] = title;
|
|
169
|
+
await persist();
|
|
170
|
+
return title;
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
/** Read and clear the pending title for one conversation, if any. */
|
|
174
|
+
async takePendingTitle(key) {
|
|
175
|
+
const titles = state().pendingTitles;
|
|
176
|
+
if (!titles || !Object.hasOwn(titles, key)) return null;
|
|
177
|
+
const title = titles[key];
|
|
178
|
+
delete titles[key];
|
|
179
|
+
if (Object.keys(titles).length === 0) delete state().pendingTitles;
|
|
180
|
+
await persist();
|
|
181
|
+
return title;
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-conversation session navigation ring.
|
|
3
|
+
*
|
|
4
|
+
* One chat keeps an ordered list ("ring") of the Harness Sessions it has bound
|
|
5
|
+
* plus a small visit stack for /go, /prev and /next. The ring is owned by the
|
|
6
|
+
* conversation (not the user), so group chats share one ring.
|
|
7
|
+
*
|
|
8
|
+
* Shape (stored per conversationKey in ConversationStateStore):
|
|
9
|
+
*
|
|
10
|
+
* {
|
|
11
|
+
* next: <int>, // next unused entry number; only grows
|
|
12
|
+
* entries: [{ n, sessionId, title?, lastSeenAt? }],
|
|
13
|
+
* visits: [n, ...], // entry numbers in visit order
|
|
14
|
+
* visitIndex: <int>, // current position in visits, -1 when none
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* Entry numbers start at 1 per conversation, only grow, and are never reused:
|
|
18
|
+
* /drop leaves a hole. The entries array stays ordered by number.
|
|
19
|
+
*
|
|
20
|
+
* These functions are pure and mutate the ring object they are handed; the
|
|
21
|
+
* store owns persistence and passes its live ring. Reads through the store are
|
|
22
|
+
* cloned, so a caller can never mutate persisted state without the store.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export function createEmptySessionRing() {
|
|
26
|
+
return { next: 1, entries: [], visits: [], visitIndex: -1 };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function finiteTimestamp(value) {
|
|
30
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Defensive loader: a ring read from disk is rebuilt field by field so a
|
|
35
|
+
* malformed or foreign document can never break navigation.
|
|
36
|
+
*/
|
|
37
|
+
export function normalizeSessionRing(value) {
|
|
38
|
+
const ring = createEmptySessionRing();
|
|
39
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return ring;
|
|
40
|
+
if (Number.isSafeInteger(value.next) && value.next >= 1) ring.next = value.next;
|
|
41
|
+
if (Array.isArray(value.entries)) {
|
|
42
|
+
for (const item of value.entries) {
|
|
43
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) continue;
|
|
44
|
+
if (!Number.isSafeInteger(item.n) || item.n < 1) continue;
|
|
45
|
+
if (typeof item.sessionId !== 'string' || !item.sessionId) continue;
|
|
46
|
+
const entry = { n: item.n, sessionId: item.sessionId };
|
|
47
|
+
if (typeof item.title === 'string' && item.title) entry.title = item.title;
|
|
48
|
+
if (item.userTitled === true) entry.userTitled = true;
|
|
49
|
+
const lastSeenAt = finiteTimestamp(item.lastSeenAt);
|
|
50
|
+
if (lastSeenAt !== null) entry.lastSeenAt = lastSeenAt;
|
|
51
|
+
ring.entries.push(entry);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
ring.entries.sort((left, right) => left.n - right.n);
|
|
55
|
+
if (Array.isArray(value.visits)) {
|
|
56
|
+
ring.visits = value.visits.filter((n) => Number.isSafeInteger(n) && n >= 1);
|
|
57
|
+
}
|
|
58
|
+
if (Number.isSafeInteger(value.visitIndex)) {
|
|
59
|
+
ring.visitIndex = value.visitIndex;
|
|
60
|
+
}
|
|
61
|
+
if (ring.visitIndex < -1 || ring.visitIndex >= ring.visits.length) ring.visitIndex = -1;
|
|
62
|
+
return ring;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function sessionRingEntryByNumber(ring, n) {
|
|
66
|
+
if (!ring || !Number.isSafeInteger(n)) return null;
|
|
67
|
+
return ring.entries.find((entry) => entry.n === n) ?? null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function sessionRingEntryBySessionId(ring, sessionId) {
|
|
71
|
+
if (!ring || typeof sessionId !== 'string' || !sessionId) return null;
|
|
72
|
+
return ring.entries.find((entry) => entry.sessionId === sessionId) ?? null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Record that a Session became bound to this conversation. A Session already
|
|
77
|
+
* in the ring is refreshed (lastSeenAt advanced, title updated when given);
|
|
78
|
+
* a new one is appended with the next number. Returns { entry, created }.
|
|
79
|
+
*/
|
|
80
|
+
export function ensureSessionRingEntry(ring, sessionId, { title, now = Date.now() } = {}) {
|
|
81
|
+
const at = finiteTimestamp(now) ?? Date.now();
|
|
82
|
+
const existing = sessionRingEntryBySessionId(ring, sessionId);
|
|
83
|
+
if (existing) {
|
|
84
|
+
existing.lastSeenAt = at;
|
|
85
|
+
// A user-set title must never be silently overwritten by a Host or first-
|
|
86
|
+
// prompt title; only lastSeenAt is refreshed for a user-titled entry.
|
|
87
|
+
if (typeof title === 'string' && title && existing.userTitled !== true) {
|
|
88
|
+
existing.title = title;
|
|
89
|
+
}
|
|
90
|
+
return { entry: existing, created: false };
|
|
91
|
+
}
|
|
92
|
+
const entry = { n: ring.next, sessionId, lastSeenAt: at };
|
|
93
|
+
ring.next += 1;
|
|
94
|
+
if (typeof title === 'string' && title) entry.title = title;
|
|
95
|
+
ring.entries.push(entry);
|
|
96
|
+
return { entry, created: true };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Replace the Session id of one entry in place: the number, title, and
|
|
101
|
+
* user-titled flag stay untouched, only lastSeenAt is refreshed. Used by /reset
|
|
102
|
+
* to keep the same slot while pointing at a fresh Session.
|
|
103
|
+
*/
|
|
104
|
+
export function replaceSessionRingEntry(ring, n, sessionId, { now = Date.now() } = {}) {
|
|
105
|
+
const entry = sessionRingEntryByNumber(ring, n);
|
|
106
|
+
if (!entry) return null;
|
|
107
|
+
entry.sessionId = sessionId;
|
|
108
|
+
entry.lastSeenAt = finiteTimestamp(now) ?? Date.now();
|
|
109
|
+
return entry;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Remove one entry by number, leaving a hole. Also retires it from visits. */
|
|
113
|
+
export function dropSessionRingEntry(ring, n) {
|
|
114
|
+
const index = ring.entries.findIndex((entry) => entry.n === n);
|
|
115
|
+
if (index < 0) return false;
|
|
116
|
+
ring.entries.splice(index, 1);
|
|
117
|
+
const visitIndex = ring.visits.indexOf(n);
|
|
118
|
+
if (visitIndex >= 0) {
|
|
119
|
+
ring.visits.splice(visitIndex, 1);
|
|
120
|
+
if (visitIndex < ring.visitIndex) ring.visitIndex -= 1;
|
|
121
|
+
else if (visitIndex === ring.visitIndex) ring.visitIndex = Math.min(ring.visitIndex, ring.visits.length - 1);
|
|
122
|
+
}
|
|
123
|
+
if (ring.visitIndex < -1) ring.visitIndex = -1;
|
|
124
|
+
if (ring.visitIndex >= ring.visits.length) ring.visitIndex = ring.visits.length - 1;
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Remove every entry except the one at `keepN`, so its number stays and the
|
|
130
|
+
* others disappear (and are never reused, as with a single /drop). The visit
|
|
131
|
+
* trail is rebuilt to end on the kept entry. Returns the removed count.
|
|
132
|
+
*/
|
|
133
|
+
export function dropSessionRingAllExcept(ring, keepN) {
|
|
134
|
+
const keepEntry = sessionRingEntryByNumber(ring, keepN);
|
|
135
|
+
if (!keepEntry) return 0;
|
|
136
|
+
const before = ring.entries.length;
|
|
137
|
+
ring.entries = ring.entries.filter((entry) => entry.n === keepN);
|
|
138
|
+
ring.visits = [keepN];
|
|
139
|
+
ring.visitIndex = 0;
|
|
140
|
+
return before - ring.entries.length;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function renameSessionRingEntry(ring, n, title) {
|
|
144
|
+
const entry = sessionRingEntryByNumber(ring, n);
|
|
145
|
+
if (!entry) return null;
|
|
146
|
+
entry.title = title;
|
|
147
|
+
return entry;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** /go: navigate to entry n. Truncates forward entries, then pushes/jumps. */
|
|
151
|
+
export function navigateSessionRing(ring, n) {
|
|
152
|
+
const index = ring.visits.indexOf(n);
|
|
153
|
+
if (index >= 0) {
|
|
154
|
+
ring.visits.splice(index + 1);
|
|
155
|
+
ring.visitIndex = index;
|
|
156
|
+
} else {
|
|
157
|
+
if (ring.visitIndex >= 0) ring.visits.splice(ring.visitIndex + 1);
|
|
158
|
+
ring.visits.push(n);
|
|
159
|
+
ring.visitIndex = ring.visits.length - 1;
|
|
160
|
+
}
|
|
161
|
+
return n;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Append entry n to the visit history like following a link: never truncate
|
|
166
|
+
* the forward entries, so the way back stays reachable. A duplicate occurrence
|
|
167
|
+
* is moved to the end rather than pushed twice.
|
|
168
|
+
*/
|
|
169
|
+
export function appendSessionRing(ring, n) {
|
|
170
|
+
const index = ring.visits.indexOf(n);
|
|
171
|
+
if (index >= 0) ring.visits.splice(index, 1);
|
|
172
|
+
ring.visits.push(n);
|
|
173
|
+
ring.visitIndex = ring.visits.length - 1;
|
|
174
|
+
return n;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Mark that the user set this entry's title deliberately via /title. */
|
|
178
|
+
export function markSessionRingEntryUserTitled(ring, n) {
|
|
179
|
+
const entry = sessionRingEntryByNumber(ring, n);
|
|
180
|
+
if (!entry) return null;
|
|
181
|
+
entry.userTitled = true;
|
|
182
|
+
return entry;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The entry /prev would walk to, or null at the beginning. */
|
|
186
|
+
export function sessionRingBackTarget(ring) {
|
|
187
|
+
return ring.visitIndex > 0 ? ring.visits[ring.visitIndex - 1] : null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The entry /next would walk to, or null at the end. */
|
|
191
|
+
export function sessionRingForwardTarget(ring) {
|
|
192
|
+
return ring.visitIndex >= 0 && ring.visitIndex < ring.visits.length - 1
|
|
193
|
+
? ring.visits[ring.visitIndex + 1]
|
|
194
|
+
: null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Commit a /prev or /next step: point visitIndex at n without truncating. */
|
|
198
|
+
export function stepSessionRingTo(ring, n) {
|
|
199
|
+
const index = ring.visits.indexOf(n);
|
|
200
|
+
if (index >= 0) ring.visitIndex = index;
|
|
201
|
+
return index;
|
|
202
|
+
}
|
|
@@ -72,3 +72,14 @@ export function initialSessionTitle({ text, content, files } = {}) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export const INITIAL_SESSION_TITLE_MAX_BYTES = DEFAULT_MAX_TITLE_BYTES;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Normalize a user-supplied inline title (e.g. `/new <title>`): strip control
|
|
78
|
+
* characters, collapse whitespace, trim, and truncate to the session-title byte
|
|
79
|
+
* budget. Returns null when nothing usable remains.
|
|
80
|
+
*/
|
|
81
|
+
export function normalizeSessionTitle(text) {
|
|
82
|
+
if (typeof text !== 'string') return null;
|
|
83
|
+
const cleaned = cleanTitleText(text);
|
|
84
|
+
return cleaned ? truncateTitle(cleaned, DEFAULT_MAX_TITLE_BYTES) : null;
|
|
85
|
+
}
|
|
@@ -91,8 +91,9 @@ function settledWithin(operation, timeoutMs) {
|
|
|
91
91
|
resolve(value ?? null);
|
|
92
92
|
return true;
|
|
93
93
|
};
|
|
94
|
+
// Deliberately NOT unref'd: the bound is the only thing holding this call
|
|
95
|
+
// open, so the timer must keep the loop alive until it fires.
|
|
94
96
|
const timer = setTimeout(() => finish(null), timeoutMs);
|
|
95
|
-
timer.unref?.();
|
|
96
97
|
(async () => operation())().then(finish, () => finish(null));
|
|
97
98
|
});
|
|
98
99
|
}
|
|
@@ -3,7 +3,7 @@ import { randomBytes, randomUUID } from 'node:crypto';
|
|
|
3
3
|
|
|
4
4
|
import { createDeferredDeliveryCoordinator, deferredOutcomeText } from './deferred-delivery-coordinator.mjs';
|
|
5
5
|
import { t } from './i18n.mjs';
|
|
6
|
-
import { commandHelpLines } from './command-catalog.mjs';
|
|
6
|
+
import { availableCommandCatalog, commandHelpLines, SHARED_COMMAND_CATALOG } from './command-catalog.mjs';
|
|
7
7
|
import {
|
|
8
8
|
COMMAND_PERMISSION_DENIED_MESSAGE,
|
|
9
9
|
evaluateInboundAccess,
|
|
@@ -17,6 +17,7 @@ import { runWorkspaceCommand, workspaceSwitchFailureText } from './workspace-com
|
|
|
17
17
|
import { runStatusCommand } from './status-command.mjs';
|
|
18
18
|
import { runCompactCommand } from './compact-command.mjs';
|
|
19
19
|
import { isClearCommand, runClearCommand } from './clear-command.mjs';
|
|
20
|
+
import { isResetCommand, runResetCommand } from './reset-command.mjs';
|
|
20
21
|
import { isHistoryCommand, runHistoryCommand } from './history-command.mjs';
|
|
21
22
|
import {
|
|
22
23
|
isControlCommand,
|
|
@@ -75,8 +76,18 @@ import {
|
|
|
75
76
|
setLastMessageFailure,
|
|
76
77
|
} from './message-failure.mjs';
|
|
77
78
|
import { logDeliveryFailure } from './delivery-failure-log.mjs';
|
|
79
|
+
import { appendFailureLog } from './failure-log-file.mjs';
|
|
78
80
|
import { beginStatusReaction } from './status-reaction.mjs';
|
|
79
|
-
import { startNewConversation } from './new-command.mjs';
|
|
81
|
+
import { startNewConversation, isNewCommand, newCommandTitle } from './new-command.mjs';
|
|
82
|
+
import {
|
|
83
|
+
isSessionNavCommand,
|
|
84
|
+
runSessionNavCommand,
|
|
85
|
+
} from './session-nav-command.mjs';
|
|
86
|
+
import {
|
|
87
|
+
documentSendSupported,
|
|
88
|
+
buttonPreviewSupported,
|
|
89
|
+
} from './channel-capabilities.mjs';
|
|
90
|
+
import { createActionNonce } from './action-card.mjs';
|
|
80
91
|
|
|
81
92
|
/** Cap and TTL for the in-memory workspace-picker snapshots behind button presses. */
|
|
82
93
|
const MAX_WORKSPACE_CARDS = 50;
|
|
@@ -183,6 +194,10 @@ function pendingMessageId(key, messageId) {
|
|
|
183
194
|
|
|
184
195
|
const PENDING_RESTART_NOTICE = '排队中的消息在服务重启时被中断。为避免重复执行,未自动重放;如果该消息尚未处理,请重新发送。';
|
|
185
196
|
|
|
197
|
+
// Callback namespace for the /tail preview "Hide" button: the payload is the
|
|
198
|
+
// nonce of the preview message the bot must delete when pressed.
|
|
199
|
+
const TAIL_HIDE_CALLBACK_PREFIX = 'tailhide|';
|
|
200
|
+
|
|
186
201
|
export class TextHarnessBridge {
|
|
187
202
|
#descriptor;
|
|
188
203
|
#bot;
|
|
@@ -215,6 +230,9 @@ export class TextHarnessBridge {
|
|
|
215
230
|
#workspaceCards = new Map();
|
|
216
231
|
// Conversation key → the one picker card that is still authoritative there.
|
|
217
232
|
#workspaceCardKeys = new Map();
|
|
233
|
+
// /tail preview messages by nonce, so the "Hide" press can delete the bot's
|
|
234
|
+
// own preview message. Keyed by nonce → { target, providerMessageId }.
|
|
235
|
+
#tailPreviewMessages = new Map();
|
|
218
236
|
// Optional channel-supplied approval card controller (see HarnessApprovalQueue's
|
|
219
237
|
// render hook). Null keeps every channel's existing plain-text approval flow.
|
|
220
238
|
#approvalCard;
|
|
@@ -459,6 +477,7 @@ export class TextHarnessBridge {
|
|
|
459
477
|
const collectingBatch = normalized.kind === 'direct'
|
|
460
478
|
&& this.#batches.status(key).phase === 'collecting';
|
|
461
479
|
const commandRunner = collectingBatch ? null : isClearCommand(text) ? runClearCommand
|
|
480
|
+
: isResetCommand(text) ? runResetCommand
|
|
462
481
|
: isHistoryCommand(text) ? runHistoryCommand
|
|
463
482
|
: hasInboundFiles(normalized) ? null : isControlCommand(text)
|
|
464
483
|
? runControlCommand
|
|
@@ -769,10 +788,15 @@ export class TextHarnessBridge {
|
|
|
769
788
|
message.statusReaction?.error();
|
|
770
789
|
this.#status.lastError = error?.message ?? String(error);
|
|
771
790
|
const failure = setLastMessageFailure(this.#status, error);
|
|
791
|
+
const diagnostic = messageFailureDiagnostic(error, failure);
|
|
772
792
|
this.#logger.error?.(
|
|
773
793
|
`[dsh-im:${this.#descriptor.key}] failed to process a batch input message [${failure.referenceId}]:`,
|
|
774
|
-
|
|
794
|
+
diagnostic,
|
|
775
795
|
);
|
|
796
|
+
appendFailureLog(failure, {
|
|
797
|
+
channel: this.#descriptor.key,
|
|
798
|
+
details: diagnostic.details ?? null,
|
|
799
|
+
});
|
|
776
800
|
}).finally(() => {
|
|
777
801
|
this.#acceptedMessageIds.delete(messageId);
|
|
778
802
|
this.#commandTasks.delete(task);
|
|
@@ -1131,7 +1155,9 @@ export class TextHarnessBridge {
|
|
|
1131
1155
|
t('{label}机器人已连接 DeepSeek Harness。', { label: this.#descriptor.label }),
|
|
1132
1156
|
'',
|
|
1133
1157
|
t('直接发送文字、图片或文件即可继续当前会话。'),
|
|
1134
|
-
...commandHelpLines(this.#descriptor.key
|
|
1158
|
+
...commandHelpLines(this.#descriptor.key, availableCommandCatalog(SHARED_COMMAND_CATALOG, {
|
|
1159
|
+
supportsFork: this.#harness.supportsSessionFork?.() ?? true,
|
|
1160
|
+
})),
|
|
1135
1161
|
].join('\n'));
|
|
1136
1162
|
return;
|
|
1137
1163
|
}
|
|
@@ -1158,8 +1184,13 @@ export class TextHarnessBridge {
|
|
|
1158
1184
|
}
|
|
1159
1185
|
return;
|
|
1160
1186
|
}
|
|
1161
|
-
if (!hasImages && !hasFiles &&
|
|
1162
|
-
const receipt = await startNewConversation({
|
|
1187
|
+
if (!hasImages && !hasFiles && isNewCommand(text)) {
|
|
1188
|
+
const receipt = await startNewConversation({
|
|
1189
|
+
state: this.#state,
|
|
1190
|
+
harness: this.#harness,
|
|
1191
|
+
key: conversationKey,
|
|
1192
|
+
title: newCommandTitle(text),
|
|
1193
|
+
});
|
|
1163
1194
|
if (this.#contextHooks?.onSessionCleared) {
|
|
1164
1195
|
try {
|
|
1165
1196
|
await this.#contextHooks.onSessionCleared(conversationKey);
|
|
@@ -1171,6 +1202,46 @@ export class TextHarnessBridge {
|
|
|
1171
1202
|
await this.#bot.sendText(target, `${receipt}\n${t('请发送你的问题。')}`);
|
|
1172
1203
|
return;
|
|
1173
1204
|
}
|
|
1205
|
+
if (!hasImages && !hasFiles && isSessionNavCommand(text)) {
|
|
1206
|
+
const result = await runSessionNavCommand(
|
|
1207
|
+
text,
|
|
1208
|
+
this.#harness,
|
|
1209
|
+
this.#state,
|
|
1210
|
+
conversationKey,
|
|
1211
|
+
{ signal: this.#signal, isDirect: message.kind === 'direct' },
|
|
1212
|
+
);
|
|
1213
|
+
if (result) {
|
|
1214
|
+
await this.#presentSessionNavResult(target, result);
|
|
1215
|
+
if (result.askText) {
|
|
1216
|
+
// /go N <text>, /prev <text>, /next <text>: switch, then submit the
|
|
1217
|
+
// remainder through the ordinary prompt path. Never await the queued
|
|
1218
|
+
// follow-up here — we are inside the queue's own job, so awaiting the
|
|
1219
|
+
// next job deadlocks. The queue runs it right after this job returns.
|
|
1220
|
+
const followUp = this.#enqueueMessage(
|
|
1221
|
+
{
|
|
1222
|
+
...message,
|
|
1223
|
+
controlText: result.askText,
|
|
1224
|
+
content: result.askText,
|
|
1225
|
+
images: undefined,
|
|
1226
|
+
files: undefined,
|
|
1227
|
+
replyTo: undefined,
|
|
1228
|
+
batchSubmission: undefined,
|
|
1229
|
+
},
|
|
1230
|
+
`${messageId}-ask`,
|
|
1231
|
+
senderId,
|
|
1232
|
+
conversationKey,
|
|
1233
|
+
);
|
|
1234
|
+
followUp.catch((error) => {
|
|
1235
|
+
this.#logger.warn?.(
|
|
1236
|
+
`[dsh-im:${this.#descriptor.key}] follow-up ask after a nav command failed:`,
|
|
1237
|
+
error?.message ?? error,
|
|
1238
|
+
);
|
|
1239
|
+
this.#bot.sendText(target, t('切换后的提问发送失败,请重试。')).catch(() => undefined);
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1174
1245
|
const compactCommand = !hasImages && !hasFiles
|
|
1175
1246
|
? await runCompactCommand(
|
|
1176
1247
|
text,
|
|
@@ -1573,10 +1644,18 @@ export class TextHarnessBridge {
|
|
|
1573
1644
|
const failureText = failedBatch?.retained
|
|
1574
1645
|
? `${messageFailureText(failure)}\n\n${failedBatch.message}`
|
|
1575
1646
|
: messageFailureText(failure);
|
|
1647
|
+
const diagnostic = messageFailureDiagnostic(error, failure);
|
|
1576
1648
|
this.#logger.error?.(
|
|
1577
1649
|
`[dsh-im:${this.#descriptor.key}] failed to process a message [${failure.referenceId}]:`,
|
|
1578
|
-
|
|
1650
|
+
diagnostic,
|
|
1579
1651
|
);
|
|
1652
|
+
// A console line only survives when somebody captures stdout; a desktop
|
|
1653
|
+
// app started from the dock has no captured stream, so the reference id
|
|
1654
|
+
// the user quotes back needs a durable line of its own.
|
|
1655
|
+
appendFailureLog(failure, {
|
|
1656
|
+
channel: this.#descriptor.key,
|
|
1657
|
+
details: diagnostic.details ?? null,
|
|
1658
|
+
});
|
|
1580
1659
|
// One line per failed or unconfirmed delivery, carrying the same id the
|
|
1581
1660
|
// user will quote back: a reference id nobody can grep is useless.
|
|
1582
1661
|
logDeliveryFailure(this.#logger, this.#descriptor.key, failure, error?.deliveryEvidence);
|
|
@@ -1873,6 +1952,11 @@ export class TextHarnessBridge {
|
|
|
1873
1952
|
if (!conversationId || !senderId || !messageId || callback?.senderIsBot === true) return;
|
|
1874
1953
|
const kind = callback.kind === 'group' ? 'group' : 'direct';
|
|
1875
1954
|
const key = `${kind}:${conversationId}`;
|
|
1955
|
+
// The /tail preview "Hide" button is a stateless delete of the bot's own
|
|
1956
|
+
// message; route its namespace before any interaction bookkeeping.
|
|
1957
|
+
if (typeof callback?.data === 'string' && callback.data.startsWith(TAIL_HIDE_CALLBACK_PREFIX)) {
|
|
1958
|
+
return this.#handleTailHidePress(callback, callback.data.slice(TAIL_HIDE_CALLBACK_PREFIX.length));
|
|
1959
|
+
}
|
|
1876
1960
|
// Workspace pickers are stateless cards, not pending questions: route their
|
|
1877
1961
|
// namespace before the question bookkeeping so a press can never touch it.
|
|
1878
1962
|
const workspacePress = this.#workspaceCard?.parse?.(callback.data) ?? null;
|
|
@@ -1964,6 +2048,81 @@ export class TextHarnessBridge {
|
|
|
1964
2048
|
});
|
|
1965
2049
|
}
|
|
1966
2050
|
|
|
2051
|
+
/**
|
|
2052
|
+
* Render a session-navigation command result. Text replies are split and sent
|
|
2053
|
+
* as-is; a /tail preview may carry a Hide button on button-capable channels;
|
|
2054
|
+
* a /tail export is delivered as a document on file-capable channels.
|
|
2055
|
+
*/
|
|
2056
|
+
async #presentSessionNavResult(target, result) {
|
|
2057
|
+
if (result?.document) {
|
|
2058
|
+
if (documentSendSupported(this.#descriptor.key, this.#bot)) {
|
|
2059
|
+
try {
|
|
2060
|
+
await this.#bot.sendFile(target, {
|
|
2061
|
+
fileName: result.document.fileName,
|
|
2062
|
+
mediaType: result.document.mediaType,
|
|
2063
|
+
bytes: Buffer.from(result.document.content, 'utf8'),
|
|
2064
|
+
});
|
|
2065
|
+
return;
|
|
2066
|
+
} catch (error) {
|
|
2067
|
+
this.#logger.warn?.(
|
|
2068
|
+
`[dsh-im:${this.#descriptor.key}] failed to send the /tail export:`,
|
|
2069
|
+
error?.message ?? error,
|
|
2070
|
+
);
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
await this.#bot.sendText(target, t('当前渠道不支持发送文件。'));
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
if (result?.hide === true && buttonPreviewSupported(this.#descriptor.key, this.#bot)) {
|
|
2077
|
+
await this.#sendTailPreviewWithHide(target, result);
|
|
2078
|
+
return;
|
|
2079
|
+
}
|
|
2080
|
+
for (const reply of result?.messages ?? [result?.message]) {
|
|
2081
|
+
if (reply) await this.#bot.sendText(target, reply);
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
/** Send a /tail preview with a single Hide button, falling back to plain text. */
|
|
2086
|
+
async #sendTailPreviewWithHide(target, result) {
|
|
2087
|
+
const nonce = createActionNonce(6);
|
|
2088
|
+
const markup = {
|
|
2089
|
+
inline_keyboard: [[{ text: t('隐藏消息'), callback_data: `${TAIL_HIDE_CALLBACK_PREFIX}${nonce}` }]],
|
|
2090
|
+
};
|
|
2091
|
+
let sent;
|
|
2092
|
+
try {
|
|
2093
|
+
sent = await this.#bot.sendInteractionCard(target, { text: result.message, markup });
|
|
2094
|
+
} catch (error) {
|
|
2095
|
+
this.#logger.warn?.(
|
|
2096
|
+
`[dsh-im:${this.#descriptor.key}] unable to send the /tail preview card; falling back to text:`,
|
|
2097
|
+
error?.message ?? error,
|
|
2098
|
+
);
|
|
2099
|
+
for (const reply of result.messages ?? [result.message]) {
|
|
2100
|
+
if (reply) await this.#bot.sendText(target, reply);
|
|
2101
|
+
}
|
|
2102
|
+
return;
|
|
2103
|
+
}
|
|
2104
|
+
const messageId = Array.isArray(sent?.providerMessageIds) && sent.providerMessageIds.length > 0
|
|
2105
|
+
? String(sent.providerMessageIds[0])
|
|
2106
|
+
: undefined;
|
|
2107
|
+
if (messageId) this.#tailPreviewMessages.set(nonce, { target, messageId });
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
/** Hide a /tail preview by deleting the bot's own message. Best-effort. */
|
|
2111
|
+
async #handleTailHidePress(callback, nonce) {
|
|
2112
|
+
const entry = this.#tailPreviewMessages.get(nonce);
|
|
2113
|
+
if (entry) this.#tailPreviewMessages.delete(nonce);
|
|
2114
|
+
await this.#answerInteractionCallback(callback, t('已隐藏。'));
|
|
2115
|
+
if (!entry?.messageId || typeof this.#bot.deleteMessage !== 'function') return;
|
|
2116
|
+
try {
|
|
2117
|
+
await this.#bot.deleteMessage(entry.target, entry.messageId);
|
|
2118
|
+
} catch (error) {
|
|
2119
|
+
this.#logger.warn?.(
|
|
2120
|
+
`[dsh-im:${this.#descriptor.key}] unable to delete a /tail preview:`,
|
|
2121
|
+
error?.message ?? error,
|
|
2122
|
+
);
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
|
|
1967
2126
|
/**
|
|
1968
2127
|
* Send the merged /ws listing as an interactive picker when the channel and
|
|
1969
2128
|
* the payload support one. Returns false so the caller can fall back to the
|